//Digispark_LDR_Neopixel.INO // Todd Andersen // 10-FEB-17 //Random Flash animation for Neopixel Ring Bangle Bracelet //by Dano Wall and Becky Stern for Adafruit Industries //based on the Sparkle Skirt, minus the accelerometer // https://learn.adafruit.com/neopixel-ring-bangle-bracelet/code #include #define PIXELS 4 #define PIN 3 const int LRDPin = 1; // Sensor pin = LRD int sensorValue = 0; // variable to store the value coming from the sensor const int threshold = 100; int stepMin = 5; // Smaller = Fewer and Larger = Greater int stepsMax = 20; // Smaller = Fewer and Larger = Greater int steps = (random(stepMin, stepsMax)); // Set pseudorandom step fade in / out range int twinkMin = 5; // Smaller = Shorter and Larger = Longer int twinkMax = 20; // Smaller = Shorter and Larger = Longer int twinkle = (random(twinkMin, twinkMax)); // Set pseudorandom twinkle time int pixelMin = 1; // Smaller = Less and Larger = More int pixelMax = 2; // Smaller = Less and Larger = More int numPixels = (random(pixelMin, pixelMax)); // Set pseudorandom twinkling number of pixels // Parameter 1 = number of pixels (PIXELS) // Parameter 2 = pin number (PIN, most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_RGB); // 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 // Use NEO_RGB for NeoLEDs uint8_t myColors[][3] = { {232, 100, 255}, // purple {200, 200, 020}, // yellow {255, 000, 000}, // red {255, 010, 100}, // off-red, TJA, 08-FEB-16 }; // don't edit the line below #define FAVCOLORS sizeof(myColors) / 3 void setup() { strip.begin(); strip.setBrightness(255); // Range = 000 through 255, 40 = Default, strip.show(); // Initialize all pixels to 'off' } void loop() { int sensorValue = analogRead (LRDPin); // Read the value of the LDR if ((sensorValue) > (threshold)){ return; } flashRandom:(twinkle, numPixels); // First number = 'Wait' delay, Smaller = Shorter twinkle flashRandom (twinkle, numPixels); // Second number = Number of neopixels to light at one time flashRandom (twinkle, numPixels); } void flashRandom(int wait, uint8_t howmany) { for(uint16_t i=0; i= 0; x--) { int r = red * x; r /= steps; int g = green * x; g /= steps; int b = blue * x; b /= steps; // LEDs will be off when done (they are faded to 0) strip.setPixelColor(j, strip.Color(r, g, b)); strip.show(); delay(wait); } } }