-
Notifications
You must be signed in to change notification settings - Fork 4
/
led.py
144 lines (120 loc) · 2.68 KB
/
led.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
#!/usr/bin/python3
# File name : motor.py
# Description : Control LEDs
# Website : www.adeept.com
# E-mail : [email protected]
# Author : William
# Date : 2018/10/12
import time
import RPi.GPIO as GPIO
left_R = 22
left_G = 23
left_B = 24
right_R = 10
right_G = 9
right_B = 25
on = GPIO.LOW
off = GPIO.HIGH
def both_on():
GPIO.output(left_R, on)
GPIO.output(left_G, on)
GPIO.output(left_B, on)
GPIO.output(right_R, on)
GPIO.output(right_G, on)
GPIO.output(right_B, on)
def setup():#initialization
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(left_R, GPIO.OUT)
GPIO.setup(left_G, GPIO.OUT)
GPIO.setup(left_B, GPIO.OUT)
GPIO.setup(right_R, GPIO.OUT)
GPIO.setup(right_G, GPIO.OUT)
GPIO.setup(right_B, GPIO.OUT)
both_off()
def both_off():
GPIO.output(left_R, off)
GPIO.output(left_G, off)
GPIO.output(left_B, off)
GPIO.output(right_R, off)
GPIO.output(right_G, off)
GPIO.output(right_B, off)
def side_on(side_X):
GPIO.output(side_X, on)
def side_off(side_X):
GPIO.output(side_X, off)
def police(police_time):
for i in range (1,police_time):
for i in range (1,3):
side_on(left_R)
side_on(right_B)
time.sleep(0.1)
both_off()
side_on(left_B)
side_on(right_R)
time.sleep(0.1)
both_off()
for i in range (1,5):
side_on(left_R)
side_on(right_B)
time.sleep(0.3)
both_off()
side_on(left_B)
side_on(right_R)
time.sleep(0.3)
both_off()
def red():
side_on(right_R)
side_on(left_R)
def green():
side_on(right_G)
side_on(left_G)
def blue():
side_on(right_B)
side_on(left_B)
def yellow():
red()
green()
def pink():
red()
blue()
def cyan():
blue()
green()
def side_color_on(side_X,side_Y):
GPIO.output(side_X, on)
GPIO.output(side_Y, on)
def side_color_off(side_X,side_Y):
GPIO.output(side_X, off)
GPIO.output(side_Y, off)
def turn_left(times):
for i in range(0,times):
both_off()
side_on(left_G)
side_on(left_R)
time.sleep(0.05)
both_off()
time.sleep(0.05)
def turn_right(times):
for i in range(1,times):
both_off()
side_on(right_G)
side_on(right_R)
time.sleep(0.05)
both_off()
time.sleep(0.05)
if __name__ == '__main__':
setup()
police(4)
both_on()
time.sleep(1)
both_off()
yellow()
time.sleep(5)
both_off()
pink()
time.sleep(5)
both_off()
cyan()
time.sleep(5)
both_off()