Complete the code to import the PWM class from the gpiozero library.
from gpiozero import [1]
The PWMLED class allows control of LED brightness using PWM signals.
Complete the code to create a PWMLED object on GPIO pin 18.
led = PWMLED([1])GPIO pin 18 is commonly used for PWM output on Raspberry Pi.
Fix the error in setting the LED brightness to 50%.
led.value = [1]The value property expects a float between 0 (off) and 1 (full brightness). 50% brightness is 0.5.
Fill both blanks to create a dictionary that maps brightness levels to LED values for 0%, 50%, and 100%.
brightness_levels = {0: [1], 50: [2], 100: 1.0}Brightness 0% is 0.0, 50% is 0.5, and 100% is 1.0 for the LED value.
Fill all three blanks to set the LED brightness to 75% using the dictionary and print the value.
level = 75 led.value = brightness_levels.get([1], [2]) print(f"LED brightness set to [3]")
We use the variable level to get the brightness from the dictionary. If not found, default to 0.75. Then print '75%'.