//LDRControlRandomFlashFadeNeopixel.INO // Todd Andersen // 09-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 1 #define PIN 2 const int LRDPin = A0; // Sensor pin = LRD int sensorValue = 0; // variable to store the value coming from the sensor int ledPin = 13; const int threshold = 500; 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 = 15; // Smaller = Shorter and Larger = Longer int twinkle (random(twinkMin, twinkMax)); // Set pseudorandom twinkle time int pixelMin = 1; // Smaller = Less and Larger = More int pixelMax = 4; // Smaller = Less and Larger = More int pixelCount (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 {030, 200, 200}, // blue {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(100); // Range = 000 through 100, 40 = Default, strip.show(); // Initialize all pixels to 'off' } void loop() { int sensorValue = analogRead (LRDPin); // Read the value of the LDR // LED on Nano Pin 13 as threashold indicator when OFF if ((sensorValue) <= (threshold)){ digitalWrite(ledPin, HIGH); } else{ digitalWrite(ledPin, LOW); } if ((sensorValue) > (threshold)){ return; } flashRandom:(twinkle, pixelCount); // First number = 'Wait' delay, Smaller = Shorter twinkle flashRandom (twinkle, pixelCount); // Second number = Number of neopixels to light at one time flashRandom (twinkle, pixelCount); } 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); } } }