Bird
0
0

You want to blink an LED connected to pin 17 on Raspberry Pi using Python. Which code snippet correctly blinks the LED once with a 1-second delay?

hard📝 Application Q15 of 15
Raspberry Pi - Platform
You want to blink an LED connected to pin 17 on Raspberry Pi using Python. Which code snippet correctly blinks the LED once with a 1-second delay?
Aimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) GPIO.output(17, GPIO.HIGH) time.sleep(1) GPIO.output(17, GPIO.LOW)
Bimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, 1) time.sleep(1) GPIO.output(17, 0)
Cimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.HIGH) time.sleep(1) GPIO.output(17, GPIO.LOW)
Dimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.HIGH) time.sleep(1) GPIO.output(17, GPIO.LOW)
Step-by-Step Solution
Solution:
  1. Step 1: Check pin numbering and setup

    BCM mode, import time, GPIO.setup(17, GPIO.OUT) are all correct.
  2. Step 2: Verify output and delay

    GPIO.output(17, GPIO.HIGH), time.sleep(1), GPIO.output(17, GPIO.LOW) blinks once (on for 1s then off).
  3. Step 3: Identify errors in other options

    One lacks import time (NameError on sleep); another uses BOARD mode (pin 17 ≠ BCM pin 17 physically); another sets GPIO.IN (should be OUT).
  4. Final Answer:

    import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.HIGH) time.sleep(1) GPIO.output(17, GPIO.LOW) -> Option D
  5. Quick Check:

    Use BCM mode, output pin, and time.sleep for blinking [OK]
Quick Trick: Use GPIO.HIGH/LOW with time.sleep for blinking [OK]
Common Mistakes:
  • Mixing BOARD and BCM pin numbers
  • Setting pin as input instead of output
  • Forgetting to import time module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes