Skip to content

Instantly share code, notes, and snippets.

@GreenMoonArt
Last active December 30, 2016 15:06
Show Gist options
  • Save GreenMoonArt/6a00b65467936baef8cf0daefb9a39fe to your computer and use it in GitHub Desktop.
Save GreenMoonArt/6a00b65467936baef8cf0daefb9a39fe to your computer and use it in GitHub Desktop.
Random Individual NeoPixels, color, delay
/*
Blink NeoPixels randomly: vary color and on/off timing
by @GreenMoonArt
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define numPIXELS 8
#define numCOLORS 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
randomSeed(analogRead(A5)); //use an unconnected analog input
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
//choose any colors you like - be sure to update numCOLORS accordingly
uint32_t colorArray[numCOLORS] = {strip.Color(91, 204, 222),
strip.Color(200, 204, 22),
strip.Color(191, 100, 75),
strip.Color(200, 200, 200),
strip.Color(220, 75, 35),
strip.Color(220, 220, 35),
strip.Color(240, 15, 10)
};
uint32_t offColor = strip.Color(0, 0, 0);
void loop() {
int randomPixel = random(0, numPIXELS);
int randomOnDelay = random(200, 2500);
int randomOffDelay = random(2000, 5000);
int randomColor = random(0, numCOLORS);
strip.setPixelColor(randomPixel, colorArray[randomColor]);
strip.show();
delay(randomOnDelay);
strip.setPixelColor(randomPixel, offColor);
strip.show();
delay(randomOffDelay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment