-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove_car.py
74 lines (53 loc) · 1.95 KB
/
move_car.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import readchar
class carMove():
def __init__(self):
self.Motor_R1_Pin = 18
self.Motor_R2_Pin = 16
self.Motor_L1_Pin = 11
self.Motor_L2_Pin = 13
self.t = 1
# GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(self.Motor_R1_Pin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(self.Motor_R2_Pin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(self.Motor_L1_Pin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(self.Motor_L2_Pin, GPIO.OUT, initial=GPIO.LOW)
def stop(self):
GPIO.output(self.Motor_R1_Pin, False)
GPIO.output(self.Motor_R2_Pin, False)
GPIO.output(self.Motor_L1_Pin, False)
GPIO.output(self.Motor_L2_Pin, False)
def forward(self,t):
GPIO.output(self.Motor_R1_Pin, True)
GPIO.output(self.Motor_R2_Pin, False)
GPIO.output(self.Motor_L1_Pin, True)
GPIO.output(self.Motor_L2_Pin, False)
time.sleep(t)
print('hihihhihhhihhhihiiiihihihihihihhihihihihihihihihih')
self.stop()
def backward(self):
GPIO.output(self.Motor_R1_Pin, False)
GPIO.output(self.Motor_R2_Pin, True)
GPIO.output(self.Motor_L1_Pin, False)
GPIO.output(self.Motor_L2_Pin, True)
time.sleep(self.t)
self.stop()
def turnRight(self,t):
GPIO.output(self.Motor_R1_Pin, True)
GPIO.output(self.Motor_R2_Pin, False)
GPIO.output(self.Motor_L1_Pin, False)
GPIO.output(self.Motor_L2_Pin, False)
time.sleep(t)
self.stop()
def turnLeft(self,t):
GPIO.output(self.Motor_R1_Pin, False)
GPIO.output(self.Motor_R2_Pin, False)
GPIO.output(self.Motor_L1_Pin, True)
GPIO.output(self.Motor_L2_Pin, False)
time.sleep(t)
self.stop()
def quit(self):
GPIO.cleanup()