I've spent a couple hours putting this together. Here's what it is supposed to do:
Blink 5 LEDs; Each LED will blink at a different rate. Each LED will blink X number of times (a number 1 thru 9). There is a 4 second delay at the end of the sequence, and then it will repeat it's blinking value.
I've tested it with 1 LED, and it seems to be working, except the delay/pause at the end of the sequence is not working. I can't figure out why, if someone could take a look I'd sure appreciate it.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define neopixelPIN 4
#define pixelCount 5
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(pixelCount, neopixelPIN, NEO_GRB + NEO_KHZ800);
unsigned long pixelMillis[6]; //duration since last blink of each pixel
unsigned long pixelDelay[] = {500, 1200, 800, 650, 1500}; //delay between individual blinks
unsigned long sequenceDelay = 4000; //delay before starting a new blink sequence
boolean pixelIsActive[6]; //used to track if the pixel should blink
boolean pixelOn[6]; //used to track if the pixel is currently on
int pixelBlinkCount[6] = {5, 6, 8, 4, 2}; //number of times each pixel should blink
int pixelCurrentBlink[6]; //used to track the current number of blinks for each pixel
void setup() {
Serial.begin(9600);
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
pixelIsActive[0] = true; //Testing with the first pixel
}
void loop() {
for (int i = 0; i < 6; i++) { //loop thru the 6 LEDs
if (millis() - pixelMillis[i] > pixelDelay[i]) { //is it time to blink this pixel?
pixelMillis[i] = millis(); //reset the timer for the current pixel
if (pixelIsActive[i]) { //is the pixel is active?
pixelOn[i] = !pixelOn[i]; //toggle it's state
if (pixelOn[i]) { //is the pixel now on?
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); // Moderately bright green color.
pixelCurrentBlink[i] += 1; //increase the blink count by one
}
else { //the pixel should not be on right now
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); //Turn off the pixel.
if (pixelCurrentBlink[i] == pixelBlinkCount[i]) { //have we reached the last blink in the sequence?
pixelCurrentBlink[i] = 0; //reset the sequence
pixelMillis[i] = millis() + sequenceDelay; //this should make it wait before starting up again, but it doesn't work
}
}
}
}
}
pixels.show();
}