Bird
0
0

Why is the GPIO.cleanup() call in this LED pattern code incorrect?

medium📝 Debug Q7 of 15
Raspberry Pi - LED and Button Projects
Why is the GPIO.cleanup() call in this LED pattern code incorrect?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.HIGH)
GPIO.cleanup(16)
AGPIO.setmode() must be called after setup().
BGPIO.output() cannot be called before setup().
CGPIO.cleanup() does not take pin numbers as arguments.
DGPIO.HIGH is not a valid output value.
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.cleanup() usage

    GPIO.cleanup() should be called without arguments to reset all pins; passing a pin number is incorrect.
  2. Step 2: Check other function usages

    GPIO.output() after setup() and GPIO.setmode() before setup() are correct; GPIO.HIGH is valid.
  3. Final Answer:

    GPIO.cleanup() does not take pin numbers as arguments. -> Option C
  4. Quick Check:

    cleanup() argument error = GPIO.cleanup() does not take pin numbers as arguments. [OK]
Quick Trick: Call GPIO.cleanup() without arguments [OK]
Common Mistakes:
  • Passing pins to cleanup()
  • Calling output before setup()
  • Misordering setmode() and setup()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes