I found a code script in this website generated by a user called 'Hackaholic' but when run it is not working.
It gives me the chance to enter an angle but the servomotor is not moving.
Someone suggested to write this line of code (dutycycle = ((angle/180.0) + 1.0) * 5.0) but I do not know where to replace it in the code below.
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