Bird
0
0

How would you write a Python loop using PWMLED to gradually increase LED brightness from 0 to 1 over 5 seconds?

hard📝 Application Q8 of 15
Raspberry Pi - gpiozero Library
How would you write a Python loop using PWMLED to gradually increase LED brightness from 0 to 1 over 5 seconds?
AUse a for loop incrementing brightness by 0.1 every 0.5 seconds
BSet brightness to 1 immediately and wait 5 seconds
CUse a while loop setting brightness to random values between 0 and 1
DSet brightness to 0.5 and then to 1 after 5 seconds
Step-by-Step Solution
Solution:
  1. Step 1: Understand gradual brightness increase

    To smoothly increase brightness over 5 seconds, increment brightness in small steps with delays.
  2. Step 2: Analyze options

    Use a for loop incrementing brightness by 0.1 every 0.5 seconds correctly uses a for loop with increments of 0.1 every 0.5 seconds (0.1 * 10 steps = 1, 0.5s * 10 = 5s). Options B, C, and D do not implement a smooth gradual increase.
  3. Final Answer:

    Use a for loop incrementing brightness by 0.1 every 0.5 seconds -> Option A
  4. Quick Check:

    Increment brightness in steps with delays [OK]
Quick Trick: Increment brightness gradually with timed loop [OK]
Common Mistakes:
  • Setting brightness instantly without gradual steps
  • Using random brightness values
  • Not including delays between increments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes