Bird
0
0

This code aims to blink two LEDs alternately on GPIO pins 10 and 11, but both LEDs stay on simultaneously. What is the likely cause?

medium📝 Debug Q6 of 15
Raspberry Pi - LED and Button Projects
This code aims to blink two LEDs alternately on GPIO pins 10 and 11, but both LEDs stay on simultaneously. What is the likely cause?
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(10, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
while True:
    GPIO.output(10, GPIO.HIGH)
    GPIO.output(11, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(10, GPIO.LOW)
    GPIO.output(11, GPIO.LOW)
    time.sleep(0.5)
AThe GPIO mode is incorrectly set
BGPIO pins 10 and 11 are not set as outputs
CThe sleep time is too short to see the blinking
DBoth LEDs are turned on and off at the same time, so they never alternate
Step-by-Step Solution
Solution:
  1. Step 1: Analyze output commands

    Both LEDs are set HIGH and LOW simultaneously.
  2. Step 2: Understand blinking logic

    To alternate, one LED should be HIGH while the other is LOW, switching each cycle.
  3. Final Answer:

    Both LEDs are turned on and off at the same time, so they never alternate -> Option D
  4. Quick Check:

    Simultaneous HIGH means no alternation [OK]
Quick Trick: Alternate LEDs require opposite HIGH/LOW states [OK]
Common Mistakes:
  • Not setting pins as outputs
  • Assuming sleep time affects alternation
  • Incorrect GPIO mode setting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes