Bird
0
0

Identify the error in this code snippet for controlling LED brightness:

medium📝 Debug Q6 of 15
Raspberry Pi - PWM Output
Identify the error in this code snippet for controlling LED brightness:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
pwm = GPIO.PWM(17, 1000)
pwm.start(110)
AMissing GPIO.cleanup() call
BDuty cycle value 110 is invalid (must be 0-100)
CPWM frequency 1000 is too low
DGPIO pin 17 is not set as output
Step-by-Step Solution
Solution:
  1. Step 1: Check duty cycle range

    Duty cycle must be between 0 and 100; 110 is invalid and causes error.
  2. Step 2: Verify other code parts

    Pin 17 is set as output; frequency 1000 Hz is valid; cleanup is optional here.
  3. Final Answer:

    Duty cycle value 110 is invalid (must be 0-100) -> Option B
  4. Quick Check:

    Duty cycle range = 0-100 [OK]
Quick Trick: Duty cycle must be 0 to 100 percent [OK]
Common Mistakes:
  • Using duty cycle above 100
  • Ignoring duty cycle limits
  • Thinking cleanup is mandatory before start

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes