0
0
Raspberry Piprogramming~5 mins

Button with interrupt (GPIO.add_event_detect) in Raspberry Pi - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AGPIO.RISING
BGPIO.PIN
CGPIO.MODE
DGPIO.CALLBACK
Which argument lets you run a function automatically when a button event is detected?
Acallback
Bevent
Cpin
Dmode
Why is debouncing needed when using button interrupts?
ATo detect long presses
BTo speed up the program
CTo change the button's voltage
DTo prevent multiple triggers from one press
What happens if you don't use interrupts and check button state in a loop?
AThe program runs faster
BThe button won't work
CThe program wastes CPU time constantly checking
DThe button triggers automatically
Which event type detects when a button is released (goes from high to low)?
AGPIO.RISING
BGPIO.FALLING
CGPIO.BOTH
DGPIO.NONE
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.