Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkfinger/440aeec8a6fe38d8e69f to your computer and use it in GitHub Desktop.
Save funkfinger/440aeec8a6fe38d8e69f to your computer and use it in GitHub Desktop.
Demo of NeoPixel library not working as expected
// example sketch to demonstrate percieved neopixel library error.
// expect green > off(-ish) > blue > off > red > off > green > off(-ish) > blue > off > red
// get green > off(-ish) > blue > off > red > off > off > off > blue > off > red
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_RGB + NEO_KHZ800);
void setup() {
pinMode(PIN, OUTPUT);
strip.begin();
strip.setPixelColor(0, strip.Color(255,0,0));
strip.show();
}
void loop() {
uint16_t wait = 2000;
strip.setPixelColor(0, strip.Color(0,255,0)); // green
strip.setBrightness(255);
strip.show();
delay(wait);
// setting brightness to 1 is OK but pixel not 100% off
strip.setBrightness(1);
strip.show();
delay(wait);
strip.setPixelColor(0, strip.Color(0,0,255)); // blue
strip.setBrightness(255);
strip.show();
delay(wait);
// setting color to 'black' is ok...
strip.setPixelColor(0, strip.Color(0,0,0));
strip.show();
delay(wait);
strip.setPixelColor(0, strip.Color(255,0,0)); // red
strip.setBrightness(255);
strip.show();
delay(wait);
// but setting brightness to 0 kills strip
strip.setBrightness(0);
strip.show();
delay(wait);
// and we never get back brightness until we set pixel color
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment