Bird
0
0

How can you modify this code to turn on two LEDs connected to pins 17 and 27 simultaneously?

hard📝 Application Q9 of 15
Raspberry Pi - gpiozero Library
How can you modify this code to turn on two LEDs connected to pins 17 and 27 simultaneously?
from gpiozero import LED
led1 = LED(17)
led2 = LED(27)
# Your code here
Aled1.off() led2.off()
Bled1.toggle() led2.toggle()
Cled1.blink() led2.blink()
Dled1.on() led2.on()
Step-by-Step Solution
Solution:
  1. Step 1: Understand turning LEDs on simultaneously

    Calling on() on both LED objects turns them on.
  2. Step 2: Evaluate options

    led1.on() led2.on() calls on() on both LEDs. led1.off() led2.off() turns them off. led1.blink() led2.blink() blinks them. led1.toggle() led2.toggle() toggles their state, which may not guarantee on.
  3. Final Answer:

    Call on() on both LEDs to turn them on simultaneously -> Option D
  4. Quick Check:

    Use on() to switch LEDs on [OK]
Quick Trick: Call on() on each LED to turn on multiple LEDs [OK]
Common Mistakes:
  • Using off() instead of on()
  • Using toggle() without knowing current state

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes