if( ledOn ) {
// LED is already on, turn it off
digitalWrite(LEDPin, LOW);
ledOn = false;
}
else {
// LED is not on, turn it on
digitalWrite(LEDPin, HIGH);
ledOn = true;
ledTm = millis();
}
@drone
I have a problem with this code. The ledOn variable should, in my opinion, be of type int, and it should be assigned/compared to HIGH and LOW. Why? Because then you can do:
ledOn = HIGH;
digitalWrite(LEDPin, lodOn);
This assures that the state of the LED and the value of ledOn never get out of sync.
I know that you think it won't happen, but it does. A month later, you make a change to the digitalWrite statement and forget to change the following statement, and you spend a long time trying to figure out what went wrong with such a simple change.