Neopixel Arduino library, strip api q's

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
DANMDaniel
 
Posts: 24
Joined: Sun Oct 17, 2010 7:24 pm

Neopixel Arduino library, strip api q's

Post by DANMDaniel »

I'm working with the a Neopixel strip and have worked with the library a bit, though I seemingly encountered a problem and need a sanity check. If the code looks like this...it should turn one pixel on and off again (looping), right? For me it executes loop only once. I also tried invoking show() in the beginning of loop. Maybe I'm misunderstanding how brightness() works with pixel colors, but I've also had some issues with some animation code .. any insight would be much appreciated. Also the doc in the uberguide is great but didn't seem to cover what I'm trying to do here.

Code: Select all

#include <Adafruit_NeoPixel.h>
#define numPixels 9

Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, 9, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
}

void loop(){
  strip.setPixelColor(0,255,255,255);
  strip.setBrightness(255);
  strip.show();
  
  delay(2000);
      
  strip.setBrightness(0);
  strip.show();
}

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Neopixel Arduino library, strip api q's

Post by pburgess »

The brightness adjustment in the NeoPixel library is currently a 'destructive' operation -- that is, it messes around with the LED colors buffered in the Arduino's memory, not as they're issued to the strip. The setBrightness() function tries its best to rescale the colors to some semblance of their former self...but when brightness has been set to zero (as near the end of your code), it's sort of a black hole and can't be reversed (so the setBrightness() near the top of loop() has no effect).

Moving the setPixelColor() call after setPixelBrightness() is one way to achieve the desired effect.

DANMDaniel
 
Posts: 24
Joined: Sun Oct 17, 2010 7:24 pm

Re: Neopixel Arduino library, strip api q's

Post by DANMDaniel »

Thanks for clearing that up...so I'm guessing that function was designed to be used sparsely and not for fade code?

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Neopixel Arduino library, strip api q's

Post by pburgess »

Exactly, yep. Usually just after strip.begin() and never again...but I may need to re-think that as people do unexpected new things.

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

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