-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotor.py
54 lines (45 loc) · 1.02 KB
/
motor.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
46
47
48
49
50
51
52
53
54
import RPi.GPIO as io
import sys, tty, termios, time
io.setmode(io.BCM)
in1_pin = 4
in2_pin = 17
io.setup(in1_pin, io.OUT)
io.setup(in2_pin, io.OUT)
def clockwise():
io.output(in1_pin,True)
io.output(in2_pin, False)
return;
def counter_clockwise():
io.output(in1_pin, False)
io.output(in2_pin, True)
return;
def stop():
io.output(in1_pin, False)
io.output(in2_pin, False)
return;
def getch():
fd = sys.stdin.fileno()
sys.stdin.flush()
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
stop()
while True:
#cmd = raw_input("Enter Value: ")
#direction = cmd[0]
direction = getch()
print(direction)
if direction == "f":
clockwise()
direction = getch()
elif direction == "r":
counter_clockwise()
direction = getch()
else:
stop()
if direction == "a":
break