// JML flash code modified for only two blink modes: fast, slow
void flashWhenNeeded() {
if (digitalRead(ledPin) == HIGH) { // if the led is ON a it's the right time, turn it off (HIGH is on)
if (millis() - lastMillis >= onTime) { // check on time and turn LED off if time has expired
lastMillis += onTime; // Add the value of onTime to lastMillis ready to start the next timing interval
digitalWrite(ledPin, LOW); // Turn LED off
}
} else { // LED is off, if it's the right time, turn it on
if (millis() - lastMillis >= offTime) { // check off time and turn LED on if time has expired
lastMillis += offTime; // Add the value of offTime to lastMillis ready to start the next timing interval
digitalWrite(ledPin, HIGH); // Turn LED on
}
}
}
/*
FlashingLed leds[] = {
{2, 500, 500}, // pin 2, 500ms ON and 500 ms OFF
{3, 1750, 350} // pin 3, 1750ms ON and 350ms OFF
};
*/
void setup() {
Serial.begin(115200);
Serial.println(F(__FILE__));
for (auto &l : leds) l.begin();
Serial.println("Setup complete");
}
void loop() {
for (auto &l : leds) l.flashWhenNeeded();
}