← Back to all lessons

Control a Button

Recommended before this lesson:

Make a Choice ↗, Blink an LED ↗

Your objective

Translations are draft and need educator review.

    Drag blocks from the toolbox into the workspace. Connect statement blocks beneath Start. Use the zoom controls to see your program.

    Loading workspace…

    Local Storage Only
    Saved on this browser only. Cloud project storage is not configured in this environment.

    Ready

    Run with the button released, press, then release. Let all 40 polls finish.

    Stop ends the current run and keeps the current device state. Reset clears the device and output, keeping blocks.

    Virtual LED

    Teaching model: external active-high LED on GPIO 2 (HIGH = ON). Real board wiring differs. This simulation does not verify physical firmware.

    OFF · Ready · 0 ms

    Execution output

      Simulated inputs

      LED 1 (GPIO 2): OFF

      Teaching model: LED GPIO 2 and buzzer indicator GPIO 5 are active high. The button is a virtual pressed/released value; exported input values are editable examples, not physical drivers. Real wiring needs board-specific resistors and drivers. Polling is finite: 40 checks, 0.25 seconds apart (10 seconds). App limits: 10,000 steps and loop iterations, depth 32, 120 seconds total, waits 0.01–60 seconds. These limits do not apply to exported files.

      Read-only code preview

      Connect one Start and all supported blocks with valid values to preview or run.

      Editor keyboard and screen reader access has not been verified. The surrounding instructions and controls are keyboard accessible. Practical alternatives: run the preloaded starter program, import/export workspace JSON, or inspect the read-only JavaScript, MicroPython, and C++ code preview.