Recall & Review
beginner
What does
GPIO.add_event_detect do in Raspberry Pi programming?It sets up an interrupt to watch a GPIO pin for a specific event, like a button press, so the program can react immediately without constantly checking the pin.
Click to reveal answer
beginner
Why use interrupts with buttons instead of checking the button state in a loop?
Interrupts let the program respond instantly when the button is pressed, saving CPU time and making the program more efficient and responsive.Click to reveal answer
intermediate
What are the common event types you can detect with
GPIO.add_event_detect?You can detect GPIO.RISING (button press going from low to high), GPIO.FALLING (high to low), or GPIO.BOTH (any change).
Click to reveal answer
intermediate
How do you attach a function to run when a button press is detected using
GPIO.add_event_detect?Use the
callback parameter to give the function name. This function runs automatically when the event happens.Click to reveal answer
intermediate
What is 'debounce' and why is it important when using button interrupts?
Debounce is a short delay to ignore extra signals caused by the button's mechanical bounce, preventing multiple unwanted triggers.
Click to reveal answer
What parameter do you use with
GPIO.add_event_detect to specify the event type?✗ Incorrect
GPIO.RISING, GPIO.FALLING, or GPIO.BOTH specify the event type to detect.
Which argument lets you run a function automatically when a button event is detected?
✗ Incorrect
The callback argument is used to assign a function to run on the event.
Why is debouncing needed when using button interrupts?
✗ Incorrect
Debouncing prevents multiple triggers caused by the button's mechanical bounce.
What happens if you don't use interrupts and check button state in a loop?
✗ Incorrect
Polling wastes CPU time and can make the program less responsive.
Which event type detects when a button is released (goes from high to low)?
✗ Incorrect
GPIO.FALLING detects when the signal goes from high to low, like a button release.
Explain how to set up a button interrupt using
GPIO.add_event_detect on a Raspberry Pi.Think about the steps to watch a pin and run code when the button changes state.
You got /4 concepts.
Describe why using interrupts with buttons is better than checking the button state in a loop.
Consider how the program behaves when waiting for a button press.
You got /4 concepts.