millis() vs delay(): blink without freezing

// WHAT YOU WILL LEARN

delay() stops the whole program; millis() lets the LED blink while the code keeps reading the knob.

// LESSON NOTES

Why does your blink code freeze the whole Arduino? ⏱️💡

1️⃣ THE PROBLEM: delay(500) means "stop and wait half a second". While it waits, NOTHING else runs — button presses and knob turns are ignored.

2️⃣ millis(): a clock that counts the milliseconds since the board powered on. Don't wait — just check it: has half a second passed?
unsigned long last = 0;
if (millis() - last >= 500) { … }

3️⃣ FLIP + NOTE THE TIME: if yes, flip the LED and save the time:
last = millis();
digitalWrite(13, !digitalRead(13));
The loop never stops, so analogRead(A0) keeps reading your knob — live!

Check the clock, don't wait!

CODE FROM THIS LESSON
unsigned long last = 0;
if (millis() - last >= 500) { … }
last = millis();
digitalWrite(13, !digitalRead(13));
Read the voiceover (transcript)
  1. Why does your blink code freeze the Arduino?
  2. Delay means stop and wait. While it waits, buttons and knobs are ignored!
  3. Millis is a clock, counting milliseconds since power on. Just check it: has half a second passed?
  4. If yes, flip the LED and note the time. The loop never stops, so the knob still works!
  5. Check the clock, don't wait!
  6. Next: two LEDs, two speeds! Follow for part thirteen!

Related lessons