Anonymous Anonymous - 1 month ago
93 0

No description

Python

Motor Control

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)

dc = 5.6

servo = GPIO.PWM(11,50)
servo.start(10)
print('***Connect Battery & Press ENTER to start')
res = raw_input()
servo.ChangeDutyCycle(5)
print('***Press ENTER to start')
res = raw_input()

print ('increase > a | decrease > z | save Wh > n | set Wh > h|quit > 9')

cycling = True
try:
    while cycling:
        servo.ChangeDutyCycle(dc)
        res = raw_input()
        if res == 'a':
            dc = dc + 0.05
        if res == 'z':
            dc = dc - 0.05
        if res == 'h':
            mymotor.setWh()
        if res == '9':
            cycling = False
finally:
    # shut down cleanly
    servo.stop()
    print ("dc var setting is: ")
    print (dc)


print('***Press ENTER to quit')
res = raw_input()
servo.stop()
GPIO.cleanup()