Hi all, I have a ws2812b strip running a christmas lights program on an arduino uno. But, in order to get the repeating pattern I wanted, I declared every single led in the strand with one each of 3 or 4 colors (it switches every 10 seconds). Is there a simpler way to accomplish this? I’d like to change the colors and possibly add more, but the way I did it is very tedious. Thabks!
Can you post your code on http://gist.github.com and put a link to it here so we can better understand what you’re doing to?
Give me a bit. Gotta finish work and learn how github works.
Remember, http://gist.github.com and http://www.github.com are different things. Gist is just a copy/paste site. Oh, and the code doesn’t need to be tedious. Before writing your own, you might want to see about downloading some of the dozens of examples already available. Marc, myself and several others have some pretty nice ones.
I copied and pasted from a TWIT Know-How project, then goofed with it till it did what I wanted. I guess the real problem here is that I don’t know how to set up an array or use a for loop. I literally copied and pasted the first 3 and 4 color setups until I had all 115, then changed the address of each in the code.
It works… Thats not the issue. Pride is the problem. I know it should be more elegant, and instead I used the equivalent of a big hammer on a gold chain bracelet. It worked… But it sure is ugly. Lol.
We all started at the beginning and didn’t know diddly so don’t worry about it. Making your project work is a fine first step. Learning /how/ it works so you can make it easier on yourself is next. And messing with some existing code can be a great way to learn how this or that effects things and get a feel for how a sketch is put together and organized.
Some basics:
https://www.arduino.cc/en/Reference/For
After you understand for loops you will see how they are often used to quickly do something to each pixel number so you don’t have to type them all out.
https://www.arduino.cc/en/Reference/Array
In a FastLED sketch you will probably always see these two lines somewhere near the top:
#define NUM_LEDS 32
and
CRGB leds[NUM_LEDS];
The CRGB leds[NUM_LEDS]; line is creating a special sort of array, and it’s size is based on the variable NUM_LEDS (which is the number of pixels in your LED strip). This is the key that allows you to address a specific pixel along your strip. For example the first pixel is leds[0], and the second leds[1]. Instead of putting a number in the brackets a variable can be used, such as leds[i]. And that variable i can be incremented with a for loop so you don’t have to type them all out! Note how it is used in these examples:
Sweet! Thanks for the help! I’ll be back in the morning when I can think to work on it some more 