Bird
0
0

You want to smoothly increase LED brightness from 0% to 100% over 5 seconds using PWM on pin 18. Which code snippet correctly implements this?

hard📝 Application Q15 of 15
Raspberry Pi - PWM Output
You want to smoothly increase LED brightness from 0% to 100% over 5 seconds using PWM on pin 18. Which code snippet correctly implements this?
Aimport time for dc in range(0, 101): pwm.ChangeDutyCycle(dc) time.sleep(0.05)
Bimport time for dc in range(0, 101, 10): pwm.ChangeDutyCycle(dc) time.sleep(0.5)
Cimport time for dc in range(0, 101, 20): pwm.ChangeDutyCycle(dc) time.sleep(1)
Dimport time for dc in range(0, 51): pwm.ChangeDutyCycle(dc*2) time.sleep(0.1)
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total steps and delay

    To increase from 0 to 100 in 5 seconds smoothly, small steps with short delay are needed.
  2. Step 2: Analyze each option timing

    import time for dc in range(0, 101): pwm.ChangeDutyCycle(dc) time.sleep(0.05) uses 101 steps with 0.05s delay = 5.05s total, smooth increase.
  3. Final Answer:

    import time for dc in range(0, 101): pwm.ChangeDutyCycle(dc) time.sleep(0.05) -> Option A
  4. Quick Check:

    101 steps * 0.05s = ~5 seconds smooth ramp [OK]
Quick Trick: Use small steps with short delay for smooth brightness [OK]
Common Mistakes:
  • Using too few steps causing jumps
  • Incorrect total time calculation
  • Multiplying duty cycle incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes