Complete the code to set the PWM frequency to 1000 Hz.
pwm = GPIO.PWM(pin, [1])The frequency of PWM is set by the second argument in GPIO.PWM(). Here, 1000 Hz is the correct frequency.
Complete the code to set the PWM duty cycle to 75%.
pwm.ChangeDutyCycle([1])The duty cycle is the percentage of time the signal is ON. 75 means 75% ON time.
Fix the error in setting the PWM frequency to 0 Hz (which is invalid).
pwm = GPIO.PWM(pin, [1])Frequency cannot be zero or negative. 100 Hz is a valid frequency.
Fill both blanks to create a dictionary mapping duty cycle percentages to their ON time in milliseconds for a 1 kHz PWM signal.
on_time_ms = {dc: dc / 100 [1] 1000 / freq for dc in duty_cycles if dc [2] 0}The ON time in milliseconds is calculated as (duty cycle / 100) * 1000 / frequency. We only include duty cycles greater than 0.
Fill all three blanks to create a dictionary comprehension that maps duty cycle percentages to their OFF time in milliseconds for a given frequency.
off_time_ms = {dc: (100 - dc) / 100 [1] 1000 [2] freq [3] 0}The OFF time is calculated as (100 - duty cycle) / 100 * 1000 / frequency. We include only duty cycles greater than 0.