Bird
0
0

Which of the following correctly adds an event detection on GPIO pin 17 for a rising edge with a callback function named button_pressed?

easy📝 Syntax Q3 of 15
Raspberry Pi - LED and Button Projects

Which of the following correctly adds an event detection on GPIO pin 17 for a rising edge with a callback function named button_pressed?

AGPIO.add_event_detect(17, GPIO.FALLING, callback=button_pressed())
BGPIO.add_event_detect(17, GPIO.RISING, callback=button_pressed)
CGPIO.add_event_detect(17, GPIO.BOTH, callback='button_pressed')
DGPIO.add_event_detect(17, GPIO.RISING)
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct edge

    The question asks for rising edge detection.
  2. Step 2: Callback syntax

    The callback should be passed as a function reference without parentheses or quotes.
  3. Step 3: Check options

    GPIO.add_event_detect(17, GPIO.RISING, callback=button_pressed) uses GPIO.RISING and passes callback correctly.
  4. Final Answer:

    GPIO.add_event_detect(17, GPIO.RISING, callback=button_pressed) -> Option B
  5. Quick Check:

    Callback must be function reference, not call or string [OK]
Quick Trick: Use function name without () for callback [OK]
Common Mistakes:
  • Calling the callback function instead of passing it
  • Passing callback as a string
  • Using wrong edge detection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes