You are on page 1of 5

#include <Adafruit_NeoPixel.

h>

//#include "Adafruit_NeoPixel.h"

#include "Nextion.h"

// Which pin on the Arduino is connected to the NeoPixels?

// On a Trinket or Gemma we suggest changing this to 1

#define PIN 6

#define led 13

#define numpixels 15

//int delayval=100;

// How many NeoPixels are attached to the Arduino?

Adafruit_NeoPixel adaled = Adafruit_NeoPixel(numpixels, PIN, NEO_GRB + NEO_KHZ800);

NexButton b0 = NexButton(0,1,"b0");

NexButton b1 = NexButton(0,2,"b1");

NexText t0 = NexText(0,3,"t0");

NexSlider h0=NexSlider(0,4,"h0");

int32_t val;

int ab=0;

NexTouch *nex_listen_list[] = {

&b0,

&b1,
NULL

};

void b0PopCallback(void *ptr){

t0.setText ("State:ON");

ab=1;

void b1PopCallback(void *ptr){

t0.setText ("State:OFF");

ab=0;

void h0PopCallback(void *ptr){

t0.setText ("State:ab");

h0.getValue(&val);

}
void setup() {

Serial.begin(9600);

nexInit();

pinMode(led,OUTPUT);

//Register the pop event callback function of the components

b0.attachPop(b0PopCallback,&b0);

b1.attachPop(b1PopCallback,&b1);

h0.attachPop(b0PopCallback,&h0);

adaled.begin();

long colour()

h0.getValue(&val);

if (val < 100)

return adaled.Color(255 - val, 255 - (val * 1.55), 255 - (val * 2.55));

else if (val < 255)

{
return adaled.Color(255 - val, val, 0);

else if (val < 510)

return adaled.Color(0, 510 - val, val - 255);

else

return adaled.Color(val - 510, 0, 765 - val);

// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus
one.

void led1(){

nexLoop(nex_listen_list);

for(int i=0;i<numpixels;i++)

if(ab==1){

digitalWrite(led,HIGH);

adaled.setPixelColor(i,colour()); // color change

else if(ab==0)

{ digitalWrite(led,LOW);
adaled.setPixelColor(i, adaled.Color(0,0,0));

else

{ digitalWrite(led,LOW);

adaled.setPixelColor(i, adaled.Color(0,0,0));}

}}

void loop() {

/// h0.getValue(&val);

led1();

adaled.show();

You might also like