Blink animation on WS2812 Neopixel strip

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Petazeta
 
Posts: 6
Joined: Tue Jun 03, 2014 1:48 pm

Blink animation on WS2812 Neopixel strip

Post by Petazeta »

Hi, I've read this Neopixel tutorial but I'm still a bit confused about configuring animations.

I want to make the strip blink (even led numbers on, odd numbers off, then odd numbers on, even numbers off) at 100 or 250 milliseconds intervals with two or three color patterns (purple, yellow, white).

From the tutorial I got it clear how to set up colors for each individual pixel using "strip.setPixelColor(n, x, y, z);" and then applying changes with "strip.show();".

What I don't get is how to configure the duration for each pixel to stay on/off, so I can make the 250ms blink animation; I am not sure that "delay()" would work here.

So, for example If I code:

Code: Select all

strip.setPixelColor(0, 255, 255, 255);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 255, 255, 255);
strip.setPixelColor(3, 0, 0, 0);
...
//and so on
strip.setPixelColor(n, x, y, z);
//then
strip.show();
This would make pixels 1 and 3 ON (white color) and pixels 2 and 4 OFF (no color)

But, how can I make them stay like that for a number of milliseconds and then swap to a different state? (inverting status between odd and even leds)

And question 2, I don't really get this thing explained in the tutorial:
You can query the color of a previously-set pixel using getPixelColor():

Code: Select all

uint32_t color = strip.getPixelColor(11);
This returns a 32-bit merged color value.

The number of pixels in a previously-declared strip can be queried using numPixels():

Code: Select all

uint16_t n = strip.numPixels();
Could you provide an example for what it does?


By the way, the 50 neopixels on my strip will be split to individual leds (cut by the line drawn between them) and then connected by AWG24 braid copper wire. I don't think that the new distance between pixels (20-30cm between each pixel) is something that must be taken into account but it prefer to be sure.

Thanks for your help :)

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Blink animation on WS2812 Neopixel strip

Post by Franklin97355 »

But, how can I make them stay like that for a number of milliseconds and then swap to a different state? (inverting status between odd and even leds)
you would set a variable (lastchange) to millis() and check it each time through the loop until millis() - lastchange > 250. That would indicate the 250ms had passed and you would run the code to set the pixels in the opposite way.

Code: Select all

uint32_t color = strip.getPixelColor(11);
This would assign the value returned for pixel 11 to the variable color

Code: Select all

uint16_t n = strip.numPixels();
This would assign the number of pixels set for "strip" to the variable n

User avatar
Tissi_2
 
Posts: 20
Joined: Mon Jun 22, 2015 10:46 am

Re: Blink animation on WS2812 Neopixel strip

Post by Tissi_2 »

Is there any shorter code for addressing odd and even pixels available? Is it possible to address them with arrays?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Blink animation on WS2812 Neopixel strip

Post by adafruit_support_bill »

Code: Select all

for(int i = 0; i < strip.numPixels; i += 2)
{
    strip.setPixelColor(i, 255, 255, 255);  // even pixels
    strip.setPixelColor(i+1 , 0, 0, 0); // odd pixels
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”