LED Series Part 14 = Arduino C++ L11: add a button without freezing

// WHAT YOU WILL LEARN

delay() freezes the board so a press is missed; with millis() the loop never waits, so read the button (INPUT_PULLUP: pressed = LOW) on every pass while the LED keeps blinking.

// LESSON NOTES

Your LED blinks… then you add a button and it ignores you? Here's the fix! 🔴🟢

❌ With delay(500) the board just waits — a press during the wait is never read.
✅ With millis() the loop never waits: it spins thousands of times a second.
🔁 So read the button every time around the loop with digitalRead(2).
🧲 With INPUT_PULLUP, pin 2 sits HIGH — pressing the button joins it to GND, so pressed = LOW!
🎉 The blink keeps going AND the button answers instantly.

Read the voiceover (transcript)
  1. Your LED blinks. Add a button: ignored?
  2. With delay, the board just waits. Your press is missed!
  3. With millis, the loop spins thousands of times a second.
  4. So check the button every time around the loop.
  5. Pressed: what does pin two read?
  6. Low! The pull-up flips it.
  7. Blink keeps going, the button answers!
  8. Next: one press, five clicks? Follow for Part 15!

Related lessons