r/FastLED • u/jester101YT2020 • Jan 22 '24
Support help rainbow function not defining
hey r/FastLED i am trying to make an andonlight/stacklight i want it use 6 buttons each a different color but 5 i want to be a rainbow animation i copied the code from the demoreel and in my code i just would'nt define im qlueless on how to make it work
electronics i use : arduino nano USB-c , 500ma bread board power supply, 16 WS2812B neopixel leds, 6 push buttons, some breadboard wires
here is the code in gist,rep https://gist.github.com/jester101YT/8d36e1514f877f75ad33fc059b6b5eae
i would be very glad to have somebody explain or fix the problem
PS: i forgot to add the //comments so if my code is unreadable my excuse
2
u/johnny5canuck Jan 22 '24
I would start from scratch with your code and, instead spend a lot of time learning some of the myriad of available working examples.
First off, your rainbow function definition is inside another function. Secondly, lines 164 to 192 can be completed with a single line. Same with the others.
2
u/Marmilicious [Marc Miller] Jan 22 '24
Here's a tip to help cleanup/simplify your code a bit. To set all pixels off (to black) you can use
FastLED.clear();and then call show().On top of that, if you wanted to set all pixels off except a specific few you could first set them all black, then set just a few, and then call show(). Such as:
Info on using HSV instead of RGB to specify a color:
https://github.com/FastLED/FastLED/wiki/FastLED-HSV-Colors
https://github.com/FastLED/FastLED/wiki/Controlling-leds#set-hsv-color
And here's another way to fill a range of pixels:
Always be careful not to write pixel data past the end of the CRGB leds array. For example if you have NUM_LEDS set to 16, the last pixel you can set is leds[15]. If you try to set data past that it will cause bad things to happen in the controllers memory leading to display glitches or the controller freezing.
When you've rewritten/updated things feel free to share a link to your new code.