Coding help - basics of arduino

Newb here

I’m trying to get the basics of the coding for the 30 LED light strip (2526).

If I wanted to set up a series of commands to have the strip run one way for 10 seconds, then another way for the next 10 seconds, and so on for 2 minutes, what syntax is involved to do that?

Also is there a wiki for the list of functions, like where can I find out what ‘delay’ does or what ‘time’ is.



It sounds like you are new to the Arduino language. You can find more information about the Arduino’s delay function as well as other functions in the Arduino’s Time library on the Language Reference page from Arduino’s website.

If you have not already, it might be helpful for you to look at some of the examples in our LED strip library to see how you can use the library to set the RGB values on the LED strip. Once you get comfortable with the Arduino language, you can try modifying one of the examples (e.g. LedStripGradient.ino) to get it to do what you want. You can use millis() for timing, like keeping track of when to alternate the LED addressing direction (10 seconds), and to stop (after 2 minutes). For example, see the Blink Without Delay Tutorial on the Arduino website.

If you try writing code or modifying one of the existing examples and run into problems, you can post your complete code here, and I would be happy to take a look.

- Amanda

awesome, thanks!

How is bitshift >> used in the gradient example?

void loop()
  // Update the colors.
  byte time = millis() >> 2;
  for (uint16_t i = 0; i < LED_COUNT; i++)
    byte x = time - 8*i;
    colors[i] = rgb_color(255 - x, 255 - x, 255 - x);

it’s shifting millis() by 2, I don’t understand why. When I change the 2 to a higher number, it slows the gradient down. I don’t understand the logic going on here though.

Edit: Oh, I guess it’s trying to increase the value of millis() by shifting the value in binary to a higher value.

millis() >> 2 is equivalent to millis()/4, which slows the animation down by a factor of 4 (2^2 = 4). You could read the bitshift reference page on the Arduino website to get a better understanding of bit shifting.

- Amanda