I'm working on replacing a lighting system based on Mercury switches and I'm about 60% of the way there. I have my code working, but it's flashing all the LEDs at once rather than in groups like I need. I know why, but I can't seem to figure out how to insert a delay between each group of outputs. Ideally, I need b7a/b and b4a/b to start the sequence, followed 500 ms later by b6a/b and b3a/b, followed an additional 500 ms later by b5a/b and b2a/b, and finally completed 500 ms later by b1. The effect we're looking for is to have the lights trail one another, so by the time we get to b5/b2, b7/b4 turns back on to restart the trail. I used a tutorial from Adafruit to get this far, but I've hit a sticking point. I tried inserting a delay in the loop, but it didn't function like I was hoping it would. How would I go about delaying each group of outputs independently? My current code is below. Thanks for the assist.
class Flasher
{
// Class Member Variables
// These are intitialised at Startup
int gpoPin; // the number of gpo pin
long OnTime; // milliseconds of on-time
long OffTime; // milliseconds of off-time
// These maintain the current state
int gpoState; // gpoState used to set the GPO
unsigned long previousMillis; // will store last time GPO was updated
// Constructor - creates a flasher
// and initializes the member variables and state
public:
Flasher(int pin, long on, long off)
{
gpoPin = pin;
pinMode(gpoPin, OUTPUT);
OnTime = on;
OffTime = off;
gpoState = LOW;
previousMillis = 0;
}
void Update()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if ((gpoState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
gpoState = LOW; // Turn it Off
previousMillis = currentMillis; // Remember the Time
digitalWrite(gpoPin, gpoState); // Update the Actual GPO
}
else if ((gpoState == LOW) && (currentMillis - previousMillis >= OffTime))
{
gpoState = HIGH; // Turn it On
previousMillis = currentMillis; // Remember the Time
digitalWrite(gpoPin, gpoState); // Update the Actual GPO
}
}
};
Flasher b1(1, 1000, 1000);
Flasher b2a(2, 1000, 1000);
Flasher b2b(3, 1000, 1000);
Flasher b3a(4, 1000, 1000);
Flasher b3b(5, 1000, 1000);
Flasher b4a(6, 1000, 1000);
Flasher b4b(7, 1000, 1000);
Flasher b5a(8, 1000, 1000);
Flasher b5b(9, 1000, 1000);
Flasher b6a(10, 1000, 1000);
Flasher b6b(11, 1000, 1000);
Flasher b7a(12, 1000, 1000);
Flasher b7b(13, 1000, 1000);
void setup ()
{
}
void loop()
{
b7b.Update();
b7a.Update();
b4b.Update();
b4a.Update();
b6b.Update();
b6a.Update();
b3b.Update();
b3a.Update();
b5b.Update();
b5a.Update();
b2b.Update();
b2a.Update();
b1.Update();
}