Bird
0
0

You want to detect a button press on pin 5 and print "Pressed" only once per press, ignoring bouncing. Which approach using GPIO.input is best?

hard📝 Application Q8 of 15
Raspberry Pi - GPIO Basics with Python
You want to detect a button press on pin 5 and print "Pressed" only once per press, ignoring bouncing. Which approach using GPIO.input is best?
AUse GPIO.input(5) in a loop with a short delay and check for state change
BUse GPIO.input(5) once and print continuously while pressed
CSet pin 5 as output and write HIGH when pressed
DUse GPIO.input(5) without any delay or state check
Step-by-Step Solution
Solution:
  1. Step 1: Understand button bouncing

    Button presses cause rapid on/off signals (bouncing) that need filtering.
  2. Step 2: Use loop with delay and state change detection

    Polling GPIO.input with delay and checking for change avoids multiple prints.
  3. Final Answer:

    Use GPIO.input(5) in a loop with a short delay and check for state change -> Option A
  4. Quick Check:

    Detect state change with delay to avoid bounce noise [OK]
Quick Trick: Detect state change with delay to avoid bounce [OK]
Common Mistakes:
  • Printing continuously while pressed
  • Setting input pin as output
  • Ignoring bouncing effect
  • Reading pin without delay

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes