I know servo :
1 ms is 0 degree
1.5 ms is 90 degree
2 ms is 180 degree
I also know servo motor has period of 20 ms and PWM from 1-2 ms, but i totally confused how to calculate angle like 30 or 60 or any angle between 0-180 .
So I want to enter angle and the angle will be converted to dutycycle. than can be used in p.ChangeDutyCycle
import time
import RPi.GPIO as gpio
gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
gpio.setup(7,gpio.OUT)
pwm = gpio.PWM(7,100)
pwm.start(2.5)
def change(k):
pwm.ChangeDutyCycle(k)
time.sleep(1)
try:
while True:
k = float(raw_input("enter angle: "))
k = (1+(float(k)/180))/20
change(k)
except KeyboardInterrupt:
pwm.stop()
gpio.cleanup()
exit