Code: Select all
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
Moderators: adafruit_support_bill, adafruit
Code: Select all
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
Code: Select all
#include <Adafruit_NeoPixel.h>
#define PIN 13
// Here is where you can put in your favorite colors that will appear!
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
// R G B
uint8_t myFavoriteColors[][3] = {{27, 207, 83}, // Pink
{27, 207, 83}, // Pink
{27, 207, 83} // Pink
};
// don't edit the line below
#define FAVCOLORS sizeof(myFavoriteColors) / 3
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
int del = 110;
// Some example procedures showing how to display to the pixels:
//colorWipe(strip.Color(250, 100, 255), 100); // Purple
flashRandom(del, 10);
flashRandom(del, 15);
flashRandom(del, 20);
flashRandom(del, 15);
flashRandom(del, 1);
flashRandom(del, 18);
flashRandom(del, 16);
flashRandom(del, 30);
flashRandom(del, 5);
flashRandom(del, 12);
flashRandom(del, 6);
flashRandom(del, 10);
/* colorWipe(strip.Color(200, 0, 200), 50); // Purple
colorWipe(strip.Color(200, 200, 200), 50); // White
colorWipe(strip.Color(200, 80, 120), 50); // Pink
colorWipe(strip.Color(000, 000, 000), 50); // OFF
*/
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void flashRandom(int wait, uint8_t howmany) {
for(uint16_t i=0; i<howmany; i++) {
// pick a random favorite color!
int c = random(FAVCOLORS);
int red = myFavoriteColors[c][0];
int green = myFavoriteColors[c][1];
int blue = myFavoriteColors[c][2];
// get a random pixel from the list
int j = random(strip.numPixels());
//Serial.print("Lighting up "); Serial.println(j);
// now we will 'fade' it in 5 steps
strip.setPixelColor(j, strip.Color(red, green, blue));
strip.show();
delay(wait);
strip.setPixelColor(j, strip.Color(0, 0, 0));
strip.show();
}
// LEDs will be off when done (they are faded to 0)
}
Code: Select all
uint8_t myFavoriteColors[][3] = {{0, 100,0}, // dim green
{0, 180, 0}, // medium Green
{0, 255, 0} // bright Green