Kurse › Raspberry Pi › Stufe 7
Raspberry Pi · Einsteiger · Stufe 7 / 40
Buttons, Buzzers and Events
Read switches and simple digital sensors reliably and write event-driven GPIO programs.
Einsteiger freischalten · CHF 9.90 Stufen 1–13, einmalig, kein Abo
10 Lektionen in dieser Stufe
- Reading a Push Button with Pull-Up and Pull-Down Resistors
Explain a floating input and fix it with internal or external pulls. · Lab: Wire a button to GPIO and ground, read it with Button and observe what happens with pull_up=None and no resistor. - Polling Versus Events: when_pressed Callbacks
Replace a busy loop with callbacks that run when something happens. · Lab: Write the same button-toggles-LED program as a polling loop and as callbacks, and compare CPU use. - Taming Switch Bounce
Recognise contact bounce and remove it with bounce_time. · Lab: Count presses with and without debouncing and record how many false counts you get. - Long Presses, Double Presses and Hold Timers
Give one button several functions using hold_time and timing logic. · Lab: Make a short press toggle an LED and a two-second hold switch everything off. - Making Sound with Active and Passive Buzzers
Drive both buzzer types and play notes with TonalBuzzer. · Lab: Beep an active buzzer, then play a short scale on a passive one. - Detecting Movement with a PIR Sensor
Wire a PIR module and tune its sensitivity and hold time. · Lab: Light an LED on motion using MotionSensor and adjust both trimmers until it behaves. - Door and Window Sensing with a Reed Switch
Use a magnetic contact as a normally-closed alarm input. · Lab: Log open and close events of a box lid with timestamps. - Connecting Devices in Code with source and values
Link inputs to outputs declaratively using gpiozero's source chain. · Lab: Make an LED follow a button, then invert and combine two inputs with source tools. - Keeping Scripts Alive and Exiting Cleanly
Use pause, handle Ctrl+C and release pins on exit. · Lab: Add a clean shutdown path to an earlier script so no LED is left on. - Building a Reaction-Time Game
Combine random delays, timing and input events into a complete program. · Lab: Build a two-player game that lights an LED after a random wait and names the faster player.
Abschlussprojekt
A desk alarm that is armed and disarmed with a long button press, watches a PIR sensor and a door contact, and sounds a buzzer with a status LED.
Teile für diese Stufe
- 1 × Raspberry Pi 5 or Pi 4 set from Level 1
- 1 × Breadboard and jumper wire set from Level 6
- 4 × Tactile push button 12 mm
- 1 × Active buzzer module 3.3 V
- 1 × Passive piezo buzzer
- 1 × PIR motion sensor module
- 1 × Magnetic reed switch with magnet
- 1 × LED and resistor assortment from Level 6
In jeder Lektion legst du die passenden Teile direkt in den Warenkorb. Raspberry Pi →
Voraussetzung: Level 6: breadboard wiring, resistor calculation and gpiozero outputs.