Bird
0
0

You want to blink an LED connected to GPIO pin 12 five times with 0.5 seconds on and 0.5 seconds off. Which code snippet correctly implements this?

hard📝 Application Q8 of 15
Raspberry Pi - LED and Button Projects
You want to blink an LED connected to GPIO pin 12 five times with 0.5 seconds on and 0.5 seconds off. Which code snippet correctly implements this?
Aimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) for _ in range(5): GPIO.output(12, GPIO.HIGH) time.sleep(0.5) GPIO.output(12, GPIO.LOW) time.sleep(0.5)
Bimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) GPIO.output(12, GPIO.HIGH) time.sleep(2.5) GPIO.output(12, GPIO.LOW)
Cimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.IN) for _ in range(5): GPIO.output(12, GPIO.HIGH) time.sleep(0.5) GPIO.output(12, GPIO.LOW) time.sleep(0.5)
Dimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) GPIO.output(12, GPIO.HIGH) time.sleep(0.5) GPIO.output(12, GPIO.LOW) time.sleep(0.5)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the need for repeated on/off cycles

    Blinking 5 times requires a loop that turns LED on and off with delays.
  2. Step 2: Check code correctness

    import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) for _ in range(5): GPIO.output(12, GPIO.HIGH) time.sleep(0.5) GPIO.output(12, GPIO.LOW) time.sleep(0.5) uses a for loop with GPIO.output HIGH and LOW and 0.5s sleep, matching requirements.
  3. Final Answer:

    Option A correctly blinks LED 5 times with 0.5s intervals -> Option A
  4. Quick Check:

    Loop with GPIO.HIGH/LOW and sleep = blink [OK]
Quick Trick: Use a loop with sleep to blink LED multiple times [OK]
Common Mistakes:
  • Setting pin as input instead of output
  • Missing loop for multiple blinks
  • Not importing time module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes