Hey Todd
I fixed it with your code! Kinda-
Now when I press the button, it does light up. But each code still lights up in a 'freeze' state. When i press the button again, both codes go to the next state and 'freeze'.
I'm thinking I'm needing a loop to keep the first code running continuously until i press the button again. Which will then go to the next code. Does this sound right? Not sure my coding skills are up to par...
#include <WS2812FX.h>
#define LED_PIN 6 // digital pin used to drive the LED strip
#define LED_COUNT 240 // number of LEDs on the strip
#define Button 2
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int Program = 0;
int maxProgram = 2;
int Num = 0;
int Run = 0;
int ButtonDelay = 500;
int Program0Delay = 100;
int Program1Delay = 100;
int Program2Delay = 10;
unsigned long ButtonTime = 0;
unsigned long DelayTime = 0;
void setup() {
pinMode(Button, INPUT_PULLUP);
Serial.begin(115200);
ws2812fx.init();
ws2812fx.setBrightness(128);
// parameters: index, start, stop, mode, color, speed, reverse
//ws2812fx.setSegment(0, 0, 9, FX_MODE_BLINK, 0xFF0000, 1000, false); // segment 0 is leds 0 - 9
//ws2812fx.setSegment(1, 10, 19, FX_MODE_SCAN, 0x00FF00, 1000, false); // segment 1 is leds 10 - 19
//ws2812fx.setSegment(2, 20, 29, FX_MODE_COMET, 0x0000FF, 1000, true); // segment 2 is leds 20 - 29
ws2812fx.start();
}
void loop() {
static int lastButtonState = digitalRead(Button);
int currButtonState = digitalRead(Button);
if (currButtonState != lastButtonState)
{
delay(50); // debounce
lastButtonState = currButtonState;
if (currButtonState == LOW)
{
Num = 0;
Run = 0;
if(Program < maxProgram)
{
Program++;
for(int Num = 0; Num < 9; Num++)
{
ws2812fx.setSegment(0, 0, 9, FX_MODE_BLINK, 0xFF0000, 1000, false); // segment 0 is leds 0 - 9
}
ws2812fx.service();
}
else
{
Program = 0;
for(int Num = 10; Num < 19; Num++)
{
ws2812fx.setSegment(1, 10, 19, FX_MODE_SCAN, 0x00FF00, 1000, false); // segment 1 is leds 10 - 19
}
ws2812fx.service();
}
ButtonTime = millis();
}
}
}