0
0
Raspberry Piprogramming~20 mins

PWMLED for brightness in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PWMLED Brightness Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output brightness level?
Consider this Python code using gpiozero's PWMLED to set brightness. What brightness value will be printed?
Raspberry Pi
from gpiozero import PWMLED
led = PWMLED(17)
led.value = 0.5
print(led.value)
A0.0
BNone
C1.0
D0.5
Attempts:
2 left
💡 Hint
The value property sets brightness from 0 (off) to 1 (full brightness).
Predict Output
intermediate
2:00remaining
What happens if you set PWMLED value to 1.5?
What will happen when running this code snippet?
Raspberry Pi
from gpiozero import PWMLED
led = PWMLED(17)
led.value = 1.5
print(led.value)
AValueError is raised
Bled.value prints 0.0
Cled.value prints 1.5
Dled.value prints 1.0
Attempts:
2 left
💡 Hint
PWMLED.value must be between 0 and 1 inclusive.
🔧 Debug
advanced
2:00remaining
Why does this PWMLED code not change brightness?
This code tries to set brightness but the LED stays off. What is the problem?
Raspberry Pi
from gpiozero import PWMLED
led = PWMLED(17)
led.value = -0.1
print(led.value)
APWMLED does not support setting value directly
BLED pin 17 is wrong, so no brightness change
CNegative brightness is invalid and ignored, so LED stays off (value 0)
DThe print statement causes the LED to turn off
Attempts:
2 left
💡 Hint
Brightness values must be between 0 and 1 inclusive.
🧠 Conceptual
advanced
2:00remaining
How does PWMLED control brightness?
Which best describes how PWMLED changes LED brightness?
AIt turns the LED on and off very fast to simulate brightness levels
BIt changes the voltage supplied to the LED continuously
CIt changes the LED color to appear dimmer
DIt uses a resistor to reduce current for brightness control
Attempts:
2 left
💡 Hint
PWM means Pulse Width Modulation.
Predict Output
expert
2:00remaining
What is the final brightness value after this sequence?
What value will be printed after running this code?
Raspberry Pi
from gpiozero import PWMLED
led = PWMLED(17)
led.value = 0.3
led.value += 0.4
led.value -= 0.1
print(round(led.value, 2))
A0.0
B0.6
C0.7
D0.5
Attempts:
2 left
💡 Hint
Remember PWMLED.value clamps between 0 and 1.