Complete the code to import the PWMOutputDevice class from the gpiozero library.
from gpiozero import [1]
The PWMOutputDevice class is used to control pulse width modulation signals on Raspberry Pi GPIO pins.
Complete the code to create a PWM object on GPIO pin 17.
servo = PWMOutputDevice([1], frequency=50)
GPIO pin 17 is commonly used for PWM control of servos on Raspberry Pi.
Fix the error in setting the servo pulse width to 1.5 milliseconds.
servo.value = [1]The servo.value expects a duty cycle value between 0 and 1. At 50Hz (20ms period), 1.5ms pulse width corresponds to 1.5/20 = 0.075.
Fill both blanks to create a dictionary mapping angles to PWM values for 0 and 90 degrees.
angle_to_pwm = {0: [1], 90: [2]For servo control at 50Hz, 0.05 corresponds to ~1ms pulse (0 degrees) and 0.075 to ~1.5ms pulse (90 degrees) duty cycle.
Fill all three blanks to complete the code that sets the servo to 45 degrees using the angle_to_pwm dictionary.
angle = 45 pwm_value = (angle_to_pwm[0] + angle_to_pwm[90]) / 2 servo.value = [1]
The variable pwm_value holds the PWM value for 45 degrees, so we assign it to servo.value.