Complete the code to start PWM on pin 18 with a frequency of 1000 Hz.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) pwm = GPIO.PWM(18, [1]) pwm.start(0)
The frequency for PWM is set to 1000 Hz to control the output signal speed.
Complete the code to set the duty cycle to 75%, which controls the analog-like output level.
pwm.ChangeDutyCycle([1])The duty cycle of 75% means the signal is ON 75% of the time, simulating an analog output.
Fix the error in the code to properly stop PWM and clean up GPIO.
pwm.[1]()
GPIO.cleanup()The correct method to stop PWM is stop(). This stops the PWM signal before cleaning up GPIO.
Fill both blanks to create a dictionary comprehension that maps each brightness level to its duty cycle if the level is greater than 50.
brightness_levels = [30, 60, 90] duty_cycles = {level: [1] for level in brightness_levels if level [2] 50}
The dictionary comprehension uses the level as the duty cycle and filters levels greater than 50.
Fill all three blanks to create a dictionary comprehension that maps the uppercase level name to its duty cycle if the duty cycle is less than 80.
levels = {'low': 30, 'medium': 60, 'high': 90}
filtered = { [1]: [2] for [3] in levels.items() if [2] < 80 }The comprehension maps uppercase level names to duty cycles, filtering duty cycles less than 80.