-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservoKeyboard.py
45 lines (32 loc) · 1018 Bytes
/
servoKeyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
import RPi.GPIO as GPIO
servo = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(servo,GPIO.OUT)
p = GPIO.PWM(servo, 50)
p.start(7.5)
try:
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
while True:
#for duty_cycle in range(3, 15, 1):
# p.ChangeDutyCycle(duty_cycle)
# time.sleep(0.1)
#for duty_cycle in range(15, 3, -1):
# p.ChangeDutyCycle(duty_cycle)
# time.sleep(0.1)
char = getch()
#for degreeChange in range (10, 180, 10):
# duty_cycle = degreeChange/12
# p.ChangeDutyCycle(duty_cycle)
# time.sleep(0.2)
# print(duty_cycle)
except KeyboardInterrupt:
GPIO.cleanup()