Arduino · Einsteiger · Stufe 11 / 40
Time Without delay: millis and State Machines
Write responsive programs that do several things at once using timestamps and explicit states.
Einsteiger freischalten · CHF 9.90 Stufen 1–13, einmalig, kein Abo
10 Lektionen in dieser Stufe
- Why delay Freezes Everything Else
Demonstrate how blocking waits make inputs and outputs unresponsive. · Lab: Blink an LED with a two-second delay and show that button presses are missed. - Measuring Elapsed Time with millis and unsigned long
Read the millisecond counter and store timestamps in the correct type. · Lab: Blink an LED using a stored timestamp and interval, with a button staying responsive. - Rollover-Safe Interval Arithmetic
Write interval comparisons that keep working when the counter wraps after about 49 days. · Lab: Simulate rollover with a small 8-bit counter and prove the subtraction form survives it. - Several Independent Timers in One Loop
Run multiple periodic activities, each with its own timestamp. · Lab: Blink three LEDs at 300, 700 and 1100 ms while reading a potentiometer. - Thinking in States: Drawing a State Diagram
Describe behaviour as states, events and transitions before coding. · Lab: Draw the state diagram of a pedestrian crossing with a request button. - Implementing a State Machine with enum and switch
Translate a state diagram into an enum, a state variable and a switch. · Lab: Code the pedestrian crossing from your diagram with no delay calls. - Non-Blocking Debounce with Timestamps
Debounce inputs by time comparison instead of waiting. · Lab: Replace the delay-based debounce in a counter sketch and verify zero miscounts in 100 presses. - Detecting Short, Long and Double Presses
Classify button gestures using a small state machine. · Lab: Print SHORT, LONG or DOUBLE for each gesture on one button. - Timeouts, Retries and Fail-Safe States
Add time limits so a program never waits forever and falls back to a safe condition. · Lab: Add an inactivity timeout that returns a menu to its idle screen and silences outputs. - Splitting loop into Cooperative Task Functions
Organise a program into short task functions that each return quickly. · Lab: Restructure a sketch into readButtons, updateLogic and updateOutputs tasks and measure loop time.
Abschlussprojekt
A fully non-blocking kitchen timer with LCD, one-button short, long and double-press control, buzzer patterns and a safe timeout state.
Teile für diese Stufe
- 1 × UNO-compatible board
- 1 × USB cable matching the board
- 1 × Solderless breadboard 830 points
- 1 × Jumper wire set male-male and male-female
- 1 × LCD 16x2 with I2C backpack
- 3 × Tactile push button
- 4 × LED 5 mm assorted
- 4 × Resistor 220 ohm
- 1 × Passive buzzer
- 1 × Potentiometer 10 kilohm
In jeder Lektion legst du die passenden Teile direkt in den Warenkorb. Arduino-kompatibel →
Voraussetzung: Levels 1–10, in particular functions, switch-case, buttons, displays and the buzzer.