/ NeoPixel_Tiara / NeoPixel_Tiara.ino
NeoPixel_Tiara.ino
1 // SPDX-FileCopyrightText: 2017 Dano Wall for Adafruit Industries 2 // SPDX-FileCopyrightText: 2017 Becky Stern for Adafruit Industries 3 // 4 // SPDX-License-Identifier: MIT 5 6 //Random Flash animation for Neopixel circuits 7 //by Dano Wall and Becky Stern for Adafruit Industries 8 //based on the Sparkle Skirt, minus the accelerometer 9 #include <Adafruit_NeoPixel.h> 10 11 #define PIN 1 12 13 // Parameter 1 = number of pixels in strip 14 // Parameter 2 = pin number (most are valid) 15 // Parameter 3 = pixel type flags, add together as needed: 16 // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 17 // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 18 // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 19 // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 20 Adafruit_NeoPixel strip = Adafruit_NeoPixel(7, PIN, NEO_GRB + NEO_KHZ800); 21 22 // Here is where you can put in your favorite colors that will appear! 23 // just add new {nnn, nnn, nnn}, lines. They will be picked out randomly 24 // R G B 25 uint8_t myColors[][3] = {{232, 100, 255}, // purple 26 {200, 200, 20}, // yellow 27 {30, 200, 200}, // blue 28 }; 29 30 // don't edit the line below 31 #define FAVCOLORS sizeof(myColors) / 3 32 33 void setup() { 34 strip.begin(); 35 strip.setBrightness(40); 36 strip.show(); // Initialize all pixels to 'off' 37 } 38 39 void loop() { 40 flashRandom(5, 1); // first number is 'wait' delay, shorter num == shorter twinkle 41 flashRandom(5, 3); // second number is how many neopixels to simultaneously light up 42 flashRandom(5, 2); 43 } 44 45 void flashRandom(int wait, uint8_t howmany) { 46 47 for(uint16_t i=0; i<howmany; i++) { 48 // pick a random favorite color! 49 int c = random(FAVCOLORS); 50 int red = myColors[c][0]; 51 int green = myColors[c][1]; 52 int blue = myColors[c][2]; 53 54 // get a random pixel from the list 55 int j = random(strip.numPixels()); 56 57 // now we will 'fade' it in 5 steps 58 for (int x=0; x < 5; x++) { 59 int r = red * (x+1); r /= 5; 60 int g = green * (x+1); g /= 5; 61 int b = blue * (x+1); b /= 5; 62 63 strip.setPixelColor(j, strip.Color(r, g, b)); 64 strip.show(); 65 delay(wait); 66 } 67 // & fade out in 5 steps 68 for (int x=5; x >= 0; x--) { 69 int r = red * x; r /= 5; 70 int g = green * x; g /= 5; 71 int b = blue * x; b /= 5; 72 73 strip.setPixelColor(j, strip.Color(r, g, b)); 74 strip.show(); 75 delay(wait); 76 } 77 } 78 // LEDs will be off when done (they are faded to 0) 79 }