Recall & Review
beginner
What is a callback function in the context of a Button class?
A callback function is a function that you assign to a button to be called automatically when the button is pressed or released. It lets the program respond to button events without constantly checking the button state.
Click to reveal answer
beginner
Why use a Button class with callbacks instead of checking button state in a loop?Using callbacks lets your program wait for button presses without wasting time checking repeatedly. It makes the code cleaner and more efficient, like setting an alarm instead of watching the clock all the time.
Click to reveal answer
beginner
How do you assign a callback function to a Button object in Python on Raspberry Pi?
You create a Button object and then use its method (like when_pressed) to assign your function. For example: button.when_pressed = my_function
Click to reveal answer
intermediate
What happens if you assign multiple callbacks to the same button event?
Usually, the last callback assigned will replace the previous one, so only one function runs when the button is pressed. To run multiple actions, you can write one callback that calls other functions.
Click to reveal answer
intermediate
Explain debouncing in the context of button callbacks.
Debouncing is a way to ignore quick repeated signals caused by the button's mechanical parts bouncing. Without debouncing, your callback might run many times for one press. Libraries often handle this automatically.
Click to reveal answer
What is the main purpose of a callback function in a Button class?
✗ Incorrect
A callback function runs automatically when the button event happens, like a press.
How do you assign a callback function to a button press event in Python on Raspberry Pi?
✗ Incorrect
The correct syntax is assigning the function to button.when_pressed without parentheses.
What problem does debouncing solve in button callbacks?
✗ Incorrect
Debouncing stops multiple signals caused by mechanical bouncing.
If you assign two different functions to button.when_pressed one after another, what happens?
✗ Incorrect
The last assignment replaces the previous callback.
Why is using callbacks better than checking button state in a loop?
✗ Incorrect
Callbacks let the program wait for events efficiently without constant checking.
Describe how to create a Button object with a callback function that runs when the button is pressed on a Raspberry Pi.
Think about how you tell the button what to do when pressed.
You got /3 concepts.
Explain what debouncing is and why it is important when using button callbacks.
Imagine pressing a button and it acting like you pressed it many times quickly.
You got /3 concepts.