Every "Pause without delay" tutorial uses LED state variable to toggle the LED, so I'm wondering what's wrong with my approach and why it's not working?
unsigned long timer1 = 0;
unsigned long timer2 = 0;
const long interval = 1000;
void setup()
{
}
void loop()
{
 timer1 = millis();
 digitalWrite(13,HIGH);
 if (millis() - timer1 >= interval) digitalWrite(13,LOW);
Â
 timer2 = millis();
 digitalWrite(13,LOW);
 if (millis() - timer2 >= interval) digitalWrite(13,LOW);
}
It's very likely because the first thing the board does is light the LED -and never switches it off-.
I did read the pinned post about millis() but I'm wondering why my code isn't alternating states? It makes perfect sense to me when I try to read it in plain English
Every time around loop() (and that's a lot of times every second), you turn the LED on.
Occasionally, you turn it off, then a few microseconds later, on again.
The LED is blinking, it's just that human eyes don't work well on microsecond timescales - you should see it with an oscilloscope though.
Study this simple "winker", is turning something ON then OFF repeatedly not called toggling?
Change "pulse" and "interval" to suit.
void setup()
{
 pinMode(LED_BUILTIN,OUTPUT);
}
void loop()
{
 static unsigned long tStart = 0;
 unsigned int pulse = 50,    // ON time = 50 mS
       interval = 1000; // OFF = interval - pulse = 950 mS
 digitalWrite(LED_BUILTIN,millis() - tStart < pulse);
 if(millis() - tStart > interval)
 tStart += interval;
}