-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathlight.py
More file actions
78 lines (65 loc) · 1.92 KB
/
light.py
File metadata and controls
78 lines (65 loc) · 1.92 KB
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
"""Light (led) control for irobot create."""
import time
import create
SERIAL_PORT = "/dev/ttyUSB0"
def kitt(r, num_repeats=2):
"""Imitate Knight Rider LEDs.
Keyword arguments:
r -- robot object and serial connection.
num_repeats -- number of loops of light sequence.
Returns: nothing, changes light intensity and color.
"""
for i in range(num_repeats):
r.setLEDs(0, 255, 0, 0)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(0, 0, 0, 1)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(12, 255, 0, 0)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(0, 0, 0, 1)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(255, 255, 0, 0)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(0, 0, 0, 1)
time.sleep(.25)
r.setLEDs(0, 0, 1, 0)
time.sleep(.25)
r.setLEDs(0, 255, 0, 0)
def look_around(r, num_repeats=2):
"""Imitate looking around with power, play, and advance leds.
Keyword arguments:
r -- robot object and serial connection
num_repeats -- number of loops of light sequence.
Returns: nothing, changes leds light intensity and color.
"""
for i in range(num_repeats):
r.setLEDs(0, 255, 0, 0)
time.sleep(.05)
r.setLEDs(0, 255, 1, 0)
time.sleep(.05)
r.setLEDs(0, 255, 1, 1)
time.sleep(.05)
r.setLEDs(0, 255, 1, 0)
time.sleep(.05)
r.setLEDs(0, 255, 0, 0)
time.sleep(.05)
for i in range(num_repeats):
r.setLEDs(12, 255, 0, 0)
time.sleep(.15)
r.setLEDs(0, 0, 0, 0)
time.sleep(.05)
if __name__ == '__main__':
r = create.Create(SERIAL_PORT)
kitt(r)
look_around(r)
r.shutdown()