Bird
0
0

How can you modify a reaction time game to ignore button presses that happen before the LED lights up, using Python and GPIO?

hard📝 Application Q9 of 15
Raspberry Pi - LED and Button Projects
How can you modify a reaction time game to ignore button presses that happen before the LED lights up, using Python and GPIO?
ASet GPIO pin as output instead of input
BUse GPIO.cleanup() before reading button input
CIgnore button input until after LED is turned on by checking a flag variable
DAdd a delay after button press to debounce
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem

    Button presses before LED lights should not count as valid reactions.
  2. Step 2: Implement logic to ignore early presses

    Use a flag variable that is False before LED lights and True after. Only check button input when flag is True.
  3. Final Answer:

    Ignore button input until after LED is turned on by checking a flag variable -> Option C
  4. Quick Check:

    Use flags to control when input is accepted [OK]
Quick Trick: Use a boolean flag to enable input only after LED lights [OK]
Common Mistakes:
  • Calling GPIO.cleanup() too early
  • Setting input pin as output
  • Confusing debounce with ignoring early presses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes