I would like to beable to start and stop the animation on the lights by pressing a button.
So far i cant figure out how to do this, im mostly sure that my hardware is setup properly so i guessing im doing something wrong in my code.
anyone think that they can point me in the right direction??
thanks
- Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#define pinStrip1 7
#define pinStrip2 8
#define pinButton 2
boolean on=true;
int buttonState = 0;
Adafruit_NeoPixel Strip1 = Adafruit_NeoPixel(8, pinStrip1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel Strip2 = Adafruit_NeoPixel(8, pinStrip2, NEO_GRB + NEO_KHZ800);
void setup()
{
pinMode(pinButton, INPUT_PULLUP);
Strip2.begin();
Strip1.begin();
}
void loop()
{
buttonState = digitalRead(pinButton);
if (buttonState == HIGH)
{
if(on==true)
{
on=false;
}else{
on=true;
}
}
if (on == true)
{
runAnimation(); //call start funtion
}else{
StopAnimation(); //call stop funtion
}
delay(500);
}
static void chase1(uint32_t c) {
for(uint16_t i=0; i<Strip1.numPixels()+4; i++) {
Strip1.setPixelColor(i , c); // Draw new pixel
Strip1.setPixelColor(i-4, 0); // Erase pixel a few steps back
Strip1.show();
delay(25);
}
}
static void chase2(uint32_t c) {
for(uint16_t i=0; i<Strip2.numPixels()+4; i++) {
Strip2.setPixelColor(i , c); // Draw new pixel
Strip2.setPixelColor(i-4, 0); // Erase pixel a few steps back
Strip2.show();
delay(25);
}
}
static void runAnimation()
{
chase1(Strip1.Color(255,0,0));
chase2(Strip2.Color(255,0,0));
}
static void StopAnimation()
{
Strip1.clear();
Strip2.clear();
}