RECENTLY CHECKED
All projects →
Make a control respond · STAGE 2 OF 4

Keep a task running while an LED changes

Replace the pauses in Blink with elapsed-time checks, leaving the main loop available for an input or another task.

You needA browser for the timing model. For upload: a compatible board with a documented LED and its supported setup.

Reference checked 9 September 2026. Authored exercise; no physical build result is claimed.

Understand the change

  1. Predict the timeline

    Unlike the original Blink, this version starts LOW. Predict transitions at approximately 750, 1000, 1750 and 2000 ms before inspecting the browser timeline.

  2. Replace waiting with checking

    loop returns repeatedly. It changes the output only when the elapsed interval has passed, allowing another short task to run between transitions.

  3. Change one interval

    Change HIGH to 500 ms while keeping LOW at 750 ms. The full cycle becomes approximately 1250 ms. Do not add delay to make the timing look neater.

  4. Keep a working baseline

    If you have compatible hardware, upload the unchanged sketch first, observe it, then make the one change. Save the exact board and observed timing for the input-control stage.

THE BRIEF

A focused request to try

Use this with a suitable AI assistant. Its response will vary; compare it with the checks below.

Rewrite my Blink sketch using millis and unsigned long elapsed-time subtraction. Start LOW, wait 750 ms, then alternate HIGH for 250 ms and LOW for 750 ms. Do not use delay. Keep LED_BUILTIN. Explain why this lets loop inspect another input and why an active-low LED reverses the visible meaning of HIGH.
THE REFERENCE

Worked reference example

Read the example, predict one change, then check the result.

const unsigned long highMs = 250;
const unsigned long lowMs = 750;
unsigned long changedAt = 0;
bool highState = false;
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  changedAt = millis();
}
void loop() {
  const unsigned long now = millis();
  const unsigned long interval = highState ? highMs : lowMs;
  if (now - changedAt >= interval) {
    highState = !highState;
    changedAt = now;
    digitalWrite(LED_BUILTIN, highState ? HIGH : LOW);
  }
  // Other short, non-blocking work can run here.
}
TRY THE WORKING EXAMPLE

Step through the output timing

Step through a model of the logic. This does not run or validate physical hardware.

EVENT TRACE

TimeOutput level

Check your result

  • Default transitions begin at 750 ms LOW-to-HIGH and 1000 ms HIGH-to-LOW.
  • HIGH 500 ms plus LOW 750 ms gives a 1250 ms nominal cycle.
  • No delay call appears in the loop.

Where this can go wrong

This browser timeline models logic, not processor timing. Slow work in loop delays transitions. LED wiring may be active-low; unsigned elapsed subtraction handles normal millis rollover only when checks occur within its wrap interval.

Go to the source

Arduino Blink Without Delay. Confirm current tool instructions before using them.

Tell us where this exercise was unclear