Bird
0
0

What is wrong with this PWM code?

medium📝 Debug Q7 of 15
Raspberry Pi - PWM Output
What is wrong with this PWM code?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(19, GPIO.OUT)
pwm = GPIO.PWM(19, 500)
pwm.ChangeDutyCycle(50)
APin 19 is not set as output
BChangeDutyCycle argument must be a string
CFrequency 500 is invalid
DPWM was not started before changing duty cycle
Step-by-Step Solution
Solution:
  1. Step 1: Check PWM start method usage

    Before calling ChangeDutyCycle, PWM must be started with pwm.start(duty_cycle).
  2. Step 2: Validate other parts

    Pin 19 is output; frequency 500 is valid; ChangeDutyCycle takes number, not string.
  3. Final Answer:

    PWM was not started before changing duty cycle -> Option D
  4. Quick Check:

    Call pwm.start() before ChangeDutyCycle [OK]
Quick Trick: Always start PWM before changing duty cycle [OK]
Common Mistakes:
  • Calling ChangeDutyCycle before start
  • Passing wrong argument types
  • Not setting pin as output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes