Warum delay() alles blockiert
Sehen Sie, wie eine Pause verhindert, dass Ihr Board reagiert.
Warum delay() alles blockiert ist eine kostenlose Arduino & IoT Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Arduino & IoT Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
The Easy Pause
The delay function pauses your sketch for a set number of milliseconds. It is the simplest way to slow things down and make a blink visible.
delay(1000);What 1000 Means
delay(1000) waits one full second, since the value is in milliseconds. So delay(500) is half a second and delay(2000) is two seconds.
It Freezes the Board
The catch: delay freezes everything. While it waits, your board does nothing else at all, like a person holding their breath. 😮
Missed Button Presses
During a delay your board cannot notice a button press. Tap it mid-pause and the press is simply ignored, which feels broken to a user.
See the Problem
Here a one-second delay sits between the checks, so any press in that whole second is lost before the next read happens.
digitalRead(buttonPin);
delay(1000);Only One Task at a Time
Because delay blocks, you cannot blink an LED and watch a sensor at the same time. The whole sketch waits as one task.
Stacked Delays Add Up
Two delay calls in a row simply add together. Spread several around and your board spends most of its life frozen and unresponsive.
Fine for Simple Sketches
delay is not evil. For a single blinking LED with nothing else going on, it is perfectly clear and totally fine to use.
The Real Goal
The real goal is a non-blocking sketch that keeps reacting while it also times events. That means never freezing the loop with a long pause.
Think About Time Instead
Instead of pausing, you can ask how much time has passed and act only when enough has gone by. The loop keeps spinning meanwhile.
A Better Tool Is Coming
Soon you will meet millis, a clock that lets you measure elapsed time without freezing. It is how real projects stay responsive.
Quick Check
What is the main drawback of using delay in a sketch?
Recap
You saw that delay is simple but freezes the board, missing inputs and blocking other tasks. Next you will time events without stopping the loop. ✨
Häufig gestellte Fragen
Ist die Lektion „Warum delay() alles blockiert“ kostenlos?
Ja — der vollständige Text von „Warum delay() alles blockiert“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Arduino & IoT Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Warum delay() alles blockiert“?
Sehen Sie, wie eine Pause verhindert, dass Ihr Board reagiert. Du übst Arduino & IoT Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Arduino & IoT Academy zu starten?
Keine Vorkenntnisse erforderlich. Arduino & IoT Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Warum delay() alles blockiert“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Arduino & IoT Academy-Lektion Code schreiben und ausführen?
Ja. Jede Arduino & IoT Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- int, float, bool auf Arduino
- Warum delay() alles blockiert
- Blinken ohne delay mit millis
- Zwei Dinge gleichzeitig ausführen