Aruinians,
This might not be complicated, but I think it is.
I'm trying to find an elegant way to "Blink Without Delay" for my First Responder Vehicle project.
The main rub is that I need to be able to select different flash patterns, and have them flash without stalling out the code.
The code for the whole program is four pages long and growing, I'll try to post all the relevant excerpts:
//Relevant variable declaration
boolean lightsOn = false;
char lightColorA = 'o';
char lightColorB = 'o';
int currentMillis = millis();
int tempMillis = 0;
int blinkInterval = 250;
int offInterval = 100;
----
if(lightsOn) //lightsOn is a boolean that triggers whether the lights flash or not
{
lightBlink(); //This calls the actual flashing function
}
else
{
colorSelect('o'); //Color 'o' is actually off (colorSelect sets the color to flash)
}
----
boolean flashPatternTime(int interval) //Eventually this function will just return true to flash or false for off
//Right now it just adjusts tempMillis
{
currentMillis = millis();
if(tempMillis - interval > currentMillis)
{
tempMillis = millis();
return false;
}
else
{
return false;
}
}
void lightBlink() //This is the function for the first flash pattern, that I'm trying to unbreak
{
colorSelect(lightColorA);
flashPatternTime(blinkInterval); //This is replacing the former (temporary) delay()
colorSelect('o');
flashPatternTime(offInterval);
colorSelect(lightColorA);
flashPatternTime(blinkInterval);
colorSelect('o');
flashPatternTime(offInterval);
}
What I'm thinking of doing is creating several arrays of pre-defined flash patterns. Something like:
flashPattern1 [] = {
{1, 0, 1, 0, 2, 0 , 2}, //Color to flash (0=off, 1 & 2 are colors 1 & 2)
{0, 0, 0, 1, 0, 0, 0}} //Where we are in the sequence
That syntax may be wrong, but I think that illustrates the idea. Basically, the '1' would rotate through the second part of the array, advancing each time the timer reaches the correct point, and flashes whichever color is associated with the array above.
Does this make sense? Is there a better way?
Appreciate any help.