LED Series Part 13 / Arduino C++ L10: Two LEDs, two speeds — multitasking with millis()

// WHAT YOU WILL LEARN

Give each LED its own 'last' time and interval, so two LEDs blink at different speeds at the same time.

// LESSON NOTES

Two LEDs. Two speeds. One Arduino. ⏱️🔴🟢

❌ delay() freezes the WHOLE loop — both LEDs wait.
✅ Give each LED its own clock with millis():
if (now − lastR >= 500) → flip the red LED
if (now − lastG >= 200) → flip the green LED

The loop never waits, so both blink at their own speed — real multitasking on one chip! (Full code in the comments.)

Read the voiceover (transcript)
  1. Two LEDs, two different speeds. Can you do it?
  2. With delay, the whole loop freezes, so both LEDs wait.
  3. The trick: give each LED its own clock with millis!
  4. Red asks: have five hundred milliseconds passed? Then flip!
  5. Green asks the same, every two hundred.
  6. The loop never waits!
  7. Real multitasking on one chip!
  8. Next: add a button, no freezing! Follow for Part fourteen!

Related lessons