0Pricing
Arduino & IoT Academy · Lektion

Polling vs. Interrupts

Warum manche Ereignisse nicht auf die Schleife warten können.

Polling vs. Interrupts ist eine kostenlose Arduino & IoT Academy-Lektion auf CoddyKit. Dies ist Lektion 1 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.

Always Checking

So far your loop uses polling: it runs around and around, asking each sensor and button over and over whether anything changed.

Polling in Action

A typical poll reads a pin every pass of the loop. If the value matches what you want, you react; otherwise you simply keep looping. 🔁

if (digitalRead(buttonPin) == LOW) {
  doSomething();
}

The Hidden Cost

Polling works, but it wastes effort asking when nothing has changed. Your board burns cycles checking a pin that stays the same for a long time.

When the Loop Is Busy

If a slow task or a long delay holds the loop, a quick press can come and go before you ever read the pin again.

Events That Cannot Wait

Some signals are fast and brief: a sensor spike, an encoder edge, a short pulse. Miss the moment and the event is gone for good.

A Smarter Way

An interrupt flips the model: instead of you asking, the hardware taps your shoulder the instant something happens on a pin.

Drop Everything

When an interrupt fires, the chip pauses whatever the loop was doing, runs your handler, then returns exactly where it left off. ⚡

Never Miss the Moment

Because the hardware watches the pin for you, even a tiny pulse triggers your code. You catch events a slow loop would skip.

Free Up the Loop

With interrupts handling urgent signals, your loop stays clean and responsive, free to do its slower work without constant checking.

When Polling Is Fine

Not everything needs an interrupt. For a button a human presses slowly, polling is simpler and perfectly good enough.

Choosing the Right Tool

Reach for an interrupt when an event is fast, brief, or might arrive while the loop is busy. Otherwise polling keeps things easy.

Quick Check

Which situation is the best reason to choose an interrupt over polling?

Recap

You saw that polling keeps asking while an interrupt gets notified. Use interrupts for fast events and polling for relaxed ones. 🎉

Häufig gestellte Fragen

Ist die Lektion „Polling vs. Interrupts“ kostenlos?

Ja — der vollständige Text von „Polling vs. Interrupts“ 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 „Polling vs. Interrupts“?

Warum manche Ereignisse nicht auf die Schleife warten können. 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 1 von 4.

Wie lange dauert die Lektion „Polling vs. Interrupts“?

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

  1. Polling vs. Interrupts
  2. attachInterrupt an einem Pin
  3. Eine sichere ISR schreiben
  4. Impulse eines Encoders zählen
← Zurück zu Arduino & IoT Academy