Bird
0
0

You want to detect a button press on GPIO 23 and execute a function only once per press, avoiding multiple triggers due to button bounce. Which approach is best?

hard📝 Application Q8 of 15
Raspberry Pi - LED and Button Projects
You want to detect a button press on GPIO 23 and execute a function only once per press, avoiding multiple triggers due to button bounce. Which approach is best?
AUse GPIO.output to read button state
BUse a while loop with time.sleep to check button state repeatedly
CUse GPIO.setup with pull-down resistor only
DUse GPIO.add_event_detect with debounce time parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand button bounce problem

    Button bounce causes multiple rapid signals on press, triggering multiple events.
  2. Step 2: Identify debounce solution

    GPIO.add_event_detect supports debounce time to ignore rapid repeated signals.
  3. Step 3: Evaluate options

    Use GPIO.add_event_detect with debounce time parameter uses event detection with debounce, best for single trigger per press.
  4. Final Answer:

    Use GPIO.add_event_detect with debounce time parameter -> Option D
  5. Quick Check:

    Debounce with event detect avoids multiple triggers [OK]
Quick Trick: Use event detect with debounce for clean button press [OK]
Common Mistakes:
  • Polling in loop causes CPU waste and multiple triggers
  • Ignoring debounce causes multiple events
  • Trying to read output pin for input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes