Polling vs Interrupts
Why some events can't wait for the loop.
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();
}All lessons in this course
- Polling vs Interrupts
- attachInterrupt on a Pin
- Writing a Safe ISR
- Count Pulses from an Encoder