Bird
0
0

Find the bug in this code that prevents LED brightness control:

medium📝 Debug Q7 of 15
Raspberry Pi - PWM Output
Find the bug in this code that prevents LED brightness control:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN)
pwm = GPIO.PWM(21, 1000)
pwm.start(50)
AGPIO pin 21 is set as input instead of output
BPWM frequency 1000 is too high
CMissing pwm.ChangeDutyCycle call
DGPIO.setmode should be BOARD, not BCM
Step-by-Step Solution
Solution:
  1. Step 1: Check GPIO pin mode

    Pin 21 is set as input, but PWM requires output mode.
  2. Step 2: Confirm other code correctness

    Frequency 1000 Hz is valid; ChangeDutyCycle is optional after start; setmode BCM is acceptable.
  3. Final Answer:

    GPIO pin 21 is set as input instead of output -> Option A
  4. Quick Check:

    GPIO pin mode must be output for PWM [OK]
Quick Trick: Set GPIO pin as output for PWM [OK]
Common Mistakes:
  • Setting pin as input instead of output
  • Confusing setmode options
  • Thinking ChangeDutyCycle is mandatory immediately

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes