-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive2.py
47 lines (37 loc) · 1006 Bytes
/
drive2.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
import time
import pytz
import RPi.GPIO as GPIO
class RCTest(object):
def __init__(self):
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#17 - left , 22 - right, 27 - forward
GPIO.setup(17, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.output(17, GPIO.HIGH)
GPIO.output(22, GPIO.HIGH)
GPIO.output(27, GPIO.HIGH)
self.steer()
def __del__(self):
GPIO.cleanup()
def steer(self, dir):
if dir==2:
print("Right\n")
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(50.0/1000.0)
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.HIGH)
elif dir==1:
print("Left\n")
GPIO.output(27, GPIO.LOW)
GPIO.output(17, GPIO.LOW)
time.sleep(50.0/1000.0)
GPIO.output(27, GPIO.HIGH)
GPIO.output(17, GPIO.HIGH)
elif dir==0:
print("Forward\n")
GPIO.output(27, GPIO.LOW)
time.sleep(50.0/1000.0)
GPIO.output(27, GPIO.HIGH)