Bird
0
0

What will be the output if the following code runs?

medium📝 Predict Output Q5 of 15
Raspberry Pi - PWM Output
What will be the output if the following code runs?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
pwm = GPIO.PWM(23, 500)
pwm.start(0)
pwm.ChangeDutyCycle(50)
ALED brightness changes to 100%
BLED brightness stays at 0%
CCode throws an error on ChangeDutyCycle
DLED brightness changes to 50%
Step-by-Step Solution
Solution:
  1. Step 1: Understand pwm.start(0)

    Starting PWM with 0 duty cycle means LED is off initially.
  2. Step 2: Effect of ChangeDutyCycle(50)

    ChangeDutyCycle updates brightness to 50%, so LED brightness changes accordingly.
  3. Final Answer:

    LED brightness changes to 50% -> Option D
  4. Quick Check:

    ChangeDutyCycle updates brightness [OK]
Quick Trick: ChangeDutyCycle adjusts brightness after start [OK]
Common Mistakes:
  • Thinking LED stays off after ChangeDutyCycle
  • Expecting error on ChangeDutyCycle call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes