>>> exit()
Enter the following command to create a new files called servo.py
nano servo.py
NOTE: Don't forget to add the inverse parameter to the PWM.start function if you found it was required to make your servos move in the previous page!
import Adafruit_BBIO.PWM as PWM servo_pin = "P8_13" duty_min = 3 duty_max = 14.5 duty_span = duty_max - duty_min PWM.start(servo_pin, (100-duty_min), 60.0) while True: angle = raw_input("Angle (0 to 180 x to exit):") if angle == 'x': PWM.stop(servo_pin) PWM.cleanup() break angle_f = float(angle) duty = 100 - ((angle_f / 180) * duty_span + duty_min) PWM.set_duty_cycle(servo_pin, duty)
# python servo.py Angle (0 to 180 x to exit):90 Angle (0 to 180 x to exit):180 Angle (0 to 180 x to exit):0 Angle (0 to 180 x to exit):x #
When you want to stop the program, enter 'x'.
You may find that your servo judders at one end of its range or does not give a full 180 degree range of movement. If this is the case, try tweaking the values in duty_min and duty_max.
When you enter 'x', the PWM is stopped and 'cleanup' is run, otherwise the PWM signal would continue in the background even after the program had stopped running.