-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtank.py
169 lines (157 loc) · 3.59 KB
/
tank.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python2
#coding=utf-8
import RPi.GPIO as GPIO
import time
def init():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(40, GPIO.OUT)
def reset():
GPIO.output(11, GPIO.LOW)
GPIO.output(12, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
GPIO.output(15, GPIO.LOW)
def left_forward():
GPIO.output(11, GPIO.HIGH)
GPIO.output(12, GPIO.LOW)
def right_forward():
GPIO.output(13, GPIO.HIGH)
GPIO.output(15, GPIO.LOW)
def left_back():
GPIO.output(11, GPIO.LOW)
GPIO.output(12, GPIO.HIGH)
def right_back():
GPIO.output(13, GPIO.LOW)
GPIO.output(15, GPIO.HIGH)
def left_stop():
GPIO.output(11, GPIO.LOW)
GPIO.output(12, GPIO.LOW)
def right_stop():
GPIO.output(13, GPIO.LOW)
GPIO.output(15, GPIO.LOW)
def turret_right():
GPIO.output(16, GPIO.HIGH)
GPIO.output(18, GPIO.LOW)
def turret_left():
GPIO.output(16, GPIO.LOW)
GPIO.output(18, GPIO.HIGH)
def turret_stop():
GPIO.output(16, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
def up():
GPIO.output(21, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
def down():
GPIO.output(21, GPIO.LOW)
GPIO.output(22, GPIO.HIGH)
def gun_lock():
GPIO.output(21, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
def re_load():
GPIO.output(29, GPIO.LOW)
GPIO.output(31, GPIO.HIGH)
def gun_stop():
GPIO.output(29, GPIO.LOW)
GPIO.output(31, GPIO.LOW)
def aim_on():
GPIO.output(40, GPIO.HIGH)
def aim_off():
GPIO.output(40, GPIO.LOW)
def f():
re_load()
time.sleep(1)
gun_stop()
def shoot():
re_load()
time.sleep(5)
gun_stop()
def g():
gun_lock()
up()
time.sleep(0.8)
gun_lock()
def gun_up():
gun_lock()
up()
time.sleep(0.7)
gun_lock()
def gun_down():
gun_lock()
down()
time.sleep(0.7)
gun_lock()
def turret_left_turn():
turret_stop()
turret_left()
time.sleep(0.2)
turret_stop()
def turret_right_turn():
turret_stop()
turret_right()
time.sleep(0.2)
turret_stop()
def forward():
reset()
left_forward()
right_forward()
def back():
reset()
left_back()
right_back()
def front_left():
reset()
right_forward()
left_stop()
def left_turn():
reset()
right_forward()
left_back()
time.sleep(0.2)
reset()
def front_right():
reset()
left_forward()
right_stop()
def right_turn():
reset()
left_forward()
right_back()
time.sleep(0.2)
reset()
def stop():
reset()
def back_left():
reset()
left_stop()
right_back()
def back_right():
reset()
left_back()
right_stop()
if __name__ == "__main__":
init()
reset()
forward()
time.sleep(0.2)
back()
time.sleep(0.2)
left_turn()
time.sleep(0.2)
right_turn()
time.sleep(0.2)
left_turn()
time.sleep(0.2)
right_turn()
stop()
'''
GPIO.cleanup()
'''