Hi everyone-
First time User & poster here-
Been in the ITS (Intelligent Traffic Systems) industry for 20+ yrs. I can design, install, program & troubleshoot a traffic signal from start to finish and make it dance. BUT
I'm new to arduino and am sucking at getting this code to implement.
Wanting to be able to press a button and have the 1st code blink the LED strip (Leds 0-9) and continue blinking until I hit the button again.
Once I press the button again, then I want it to run the 2nd code (scan) the LED strip (Leds 10-19). If I press the button again, it will shut off and wait until another press and start over again this sequence.
Currently, if I hold the button down, it runs both sequences. If I unpress the button, the led strip is black. Any guidance and help is appreciated! see code below:
#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() {
if(digitalRead(Button) == LOW && millis() - ButtonTime > ButtonDelay)
{
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();
}
}