const int LEDpin = 3;
const long onDuration = 100;// OFF time for LED
const long offDuration = 500;// ON time for LED
int LEDState = HIGH; // initial state of LED
long rememberTime = 0; // this is used by the code
void setup() {
pinMode(LEDpin, OUTPUT); // define LEDpin as output
digitalWrite(LEDpin, LEDState); // set initial state
}
void loop() {
// LED blink with millis
if ( LEDState == HIGH )
{
if ( (millis() - rememberTime) >= onDuration) {
LEDState = LOW;// change the state of LED
rememberTime = millis(); // remember Current millis() time
}
}
else
{
if ( (millis() - rememberTime) >= offDuration) {
LEDState = HIGH; // change the state of LED
rememberTime = millis(); // remember Current millis() time
}
}
digitalWrite(LEDpin, LEDState); // turn the LED ON or OFF
}// loop ends