Bird
0
0

Identify the error in this Raspberry Pi LED control code:

medium📝 Debug Q14 of 15
Raspberry Pi - LED and Button Projects
Identify the error in this Raspberry Pi LED control code:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, HIGH)
GPIO.cleanup()
AGPIO.cleanup() should be called before output
BMissing import for time module
CPin 12 cannot be used as output
DIncorrect use of GPIO.HIGH without prefix
Step-by-Step Solution
Solution:
  1. Step 1: Check GPIO output command

    The code uses HIGH without GPIO. prefix, causing a NameError.
  2. Step 2: Correct usage of HIGH signal

    It should be GPIO.output(12, GPIO.HIGH) to properly reference the constant.
  3. Final Answer:

    Incorrect use of GPIO.HIGH without prefix -> Option D
  4. Quick Check:

    Use GPIO.HIGH, not just HIGH [OK]
Quick Trick: Always prefix HIGH with GPIO. [OK]
Common Mistakes:
  • Using HIGH instead of GPIO.HIGH
  • Calling cleanup before output
  • Confusing BOARD and BCM modes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes