/ Gemma_Nano_Ring / Gemma_Nano_Ring.ino
Gemma_Nano_Ring.ino
1 // SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include <Adafruit_NeoPixel.h> 6 #define PIN 1 7 #define NUM_LEDS 3 8 9 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); 10 11 // R G B 12 uint8_t myColors[][5] = { 13 {30, 144, 255}, // dodger blue 14 {232, 100, 255}, // purple 15 {204, 0, 204}, // 16 {200, 200, 20}, // yellow 17 {30, 200, 200}, // blue 18 }; 19 20 // don't edit the line below 21 #define FAVCOLORS sizeof(myColors) / 5 22 23 void setup() { 24 strip.begin(); 25 strip.setBrightness(20); 26 strip.show(); // Initialize all pixels to 'off' 27 } 28 29 void loop() { 30 flashRandom(10, 1); // first number is 'wait' delay, shorter num == shorter twinkle 31 flashRandom(10, 3); // second number is how many neopixels to simultaneously light up 32 flashRandom(10, 2); 33 } 34 35 void flashRandom(int wait, uint8_t howmany) { 36 37 for(uint16_t i=0; i<howmany; i++) { 38 // pick a random favorite color! 39 int c = random(FAVCOLORS); 40 int red = myColors[c][0]; 41 int green = myColors[c][1]; 42 int blue = myColors[c][2]; 43 44 // get a random pixel from the list 45 int j = random(strip.numPixels()); 46 47 // now we will 'fade' it in 5 steps 48 for (int x=0; x < 5; x++) { 49 int r = red * (x+1); r /= 5; 50 int g = green * (x+1); g /= 5; 51 int b = blue * (x+1); b /= 5; 52 53 strip.setPixelColor(j, strip.Color(r, g, b)); 54 strip.show(); 55 delay(wait); 56 } 57 // & fade out in 5 steps 58 for (int x=5; x >= 0; x--) { 59 int r = red * x; r /= 5; 60 int g = green * x; g /= 5; 61 int b = blue * x; b /= 5; 62 63 strip.setPixelColor(j, strip.Color(r, g, b)); 64 strip.show(); 65 delay(wait); 66 } 67 } 68 // LEDs will be off when done (they are faded to 0) 69 }