All tutorials

1 · First steps

Blink without delay() (millis)

Advanced20 min

Goal

Replace delay() with a time comparison based on millis().

Why it matters

delay() freezes the whole program. millis() lets you do several things at once.

Steps

  1. 01Declare unsigned long previous = 0; and const long interval = 1000;
  2. 02In loop(), compare millis() - previous >= interval.
  3. 03Toggle the LED state and update previous.
  4. 04Check that no delay() is left.

This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.

Next tutorials