Possibly this will be a breeze for the C Gurus !!
In the code below what change do I have to make so that I can flash the three LEDs at different rates ? Right now only the first call is active for the other two LEDs ( 2 and 3 ) ...
void setup()
{
Serial.begin(9600);
Serial.println("Blink code starts...");
}
void loop()
{
ledPrgOnOff(1000, 500, 13);
ledPrgOnOff(2000, 100, 2);
ledPrgOnOff(500, 500, 3);
}
//$$$$$$$$$$$$$$$$$$$$$
// Function to blink an LED based on programmed On Times and Off times..
void ledPrgOnOff(long onPeriod, long offPeriod, byte ledPin )
{
unsigned long currentMillis = millis();
static unsigned long previousMillis = millis();
static boolean ledState;
static boolean onLED = 1;
static boolean offLED = 0;
if ( onLED )
{
if (currentMillis - previousMillis >= onPeriod)
{
ledState = LOW;
onLED = 0;
offLED = 1;
previousMillis = currentMillis;
}
}
if ( offLED )
{
if (currentMillis - previousMillis >= offPeriod)
{
ledState = HIGH;
onLED = 1;
offLED = 0;
previousMillis = currentMillis;
}
}
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState); // Update the LED state
}