Bird
0
0

What will be the output behavior of this code controlling an LED on pin 7?

medium📝 Predict Output Q4 of 15
Raspberry Pi - Platform
What will be the output behavior of this code controlling an LED on pin 7?
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
for i in range(3):
    GPIO.output(7, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(7, GPIO.LOW)
    time.sleep(1)
AThe LED will stay on continuously for 3 seconds
BThe LED will blink on and off 3 times with 1 second intervals
CThe LED will blink rapidly without delay
DThe program will cause a runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop and GPIO commands

    The loop runs 3 times, turning the LED on, waiting 1 second, off, then waiting 1 second.
  2. Step 2: Understand the timing and LED behavior

    This causes the LED to blink on and off 3 times with 1 second intervals.
  3. Final Answer:

    The LED will blink on and off 3 times with 1 second intervals -> Option B
  4. Quick Check:

    Loop with sleep controls LED blink count and timing [OK]
Quick Trick: Loops with sleep create timed LED blinks [OK]
Common Mistakes:
  • Ignoring sleep delays
  • Assuming continuous ON
  • Confusing HIGH/LOW states

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes