Bird
0
0

You want to create a program that blinks two LEDs on pins 17 and 27 alternately every 0.5 seconds for 5 seconds total. Which code snippet correctly implements this using the LED class?

hard📝 Application Q15 of 15
Raspberry Pi - gpiozero Library

You want to create a program that blinks two LEDs on pins 17 and 27 alternately every 0.5 seconds for 5 seconds total. Which code snippet correctly implements this using the LED class?

from gpiozero import LED
from time import sleep

led1 = LED(17)
led2 = LED(27)

start = 0
while start < 5:
    led1.on()
    led2.off()
    sleep(0.5)
    led1.off()
    led2.on()
    sleep(0.5)
    start += 1

led1.off()
led2.off()
led1.close()
led2.close()
AShould use blink() method instead of manual on/off
BThe loop runs too long; should use start < 10
CThis code blinks LEDs alternately for 5 seconds correctly
DMissing sleep between led1.off() and led2.on()
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop timing and LED control

    The loop runs 5 times, each iteration takes 1 second (two 0.5s sleeps), total 5 seconds blinking alternately.
  2. Step 2: Check LED on/off sequence and cleanup

    LED1 and LED2 turn on/off alternately with proper sleep delays, and GPIO pins are closed at the end.
  3. Final Answer:

    This code blinks LEDs alternately for 5 seconds correctly -> Option C
  4. Quick Check:

    Loop count x sleep = total blink time [OK]
Quick Trick: Count loop x sleep to verify total blink time [OK]
Common Mistakes:
  • Miscounting total blink duration
  • Forgetting to close GPIO pins
  • Assuming blink() method is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes