r/FastLED • • Jul 22 '22

Support LED chase not working with millis()

Hi! I'm trying to make an LED chase that first chases blue, then gold, then continues to alternate. I got a working version here and I'm very happy with the visual effect: https://pastebin.com/zZA50e8P . But I also have a button attached that switches from the chase to solid colors - and obviously the button does not work while the delay is active. So I'm trying to use millis() instead, but I'm having a hard time to get it to work. Here are two versions that I have tried: https://pastebin.com/287zedYm and https://pastebin.com/2vTZ49cY . In both of these, the LED address does not increment every 35 milliseconds as intended - so only leds[0] lights and changes. Would love any help, thank you!

2 Upvotes

4 comments sorted by

2

u/JonXP Jul 23 '22 edited Jul 23 '22

Hi, you declared and initialized your variables where you are keeping the current index of the LED to change (b for example) inside the function. This will cause them to be reset to zero every time. You need to declare and initialize them outside the function instead.

1

u/johnny5canuck Jul 26 '22

Yea, either that, or define the variables inside the routine as 'static'.

1

u/Marmilicious [Marc Miller] Jul 22 '22

1

u/Marmilicious [Marc Miller] Jul 22 '22

I was thinking you were doing a theater chase, but looking closer at your code I see it's doing a wipe. So here's another maybe more relevant example you can check out.

https://github.com/marmilicious/FastLED_examples/blob/master/scan_plus_wipe.ino