Bird
0
0

How can you modify a Raspberry Pi LED toggle program to ignore button presses shorter than 0.5 seconds (debounce)?

hard📝 Application Q9 of 15
Raspberry Pi - LED and Button Projects
How can you modify a Raspberry Pi LED toggle program to ignore button presses shorter than 0.5 seconds (debounce)?
ARecord press time and only toggle if press duration > 0.5 seconds
BAdd a fixed delay of 0.5 seconds after every toggle regardless of press
CUse GPIO.setup with pull_down resistor instead of pull_up
DToggle LED twice quickly to confirm press
Step-by-Step Solution
Solution:
  1. Step 1: Understand debounce by filtering short presses

    Measure how long button is pressed to ignore quick accidental presses.
  2. Step 2: Implement timing logic

    Record time when button is pressed and released; toggle LED only if duration exceeds 0.5 seconds.
  3. Final Answer:

    Record press time and only toggle if press duration > 0.5 seconds -> Option A
  4. Quick Check:

    Debounce by timing press duration = A [OK]
Quick Trick: Use timing to filter out short button presses [OK]
Common Mistakes:
  • Using fixed delay without timing
  • Changing resistor type incorrectly
  • Toggling LED twice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes