-
Notifications
You must be signed in to change notification settings - Fork 4
/
wiimote_demo.py
executable file
·62 lines (53 loc) · 1.48 KB
/
wiimote_demo.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
#!/usr/bin/env python3
import wiimote
import time
import sys
"""
A simple demo script for the wiimote.py module.
Start as `python3 wiimote_demo.py [bluetooth address of Wiimote]` and follow
instructions.
"""
input("Press the 'sync' button on the back of your Wiimote Plus " +
"or buttons (1) and (2) on your classic Wiimote.\n" +
"Press <return> once the Wiimote's LEDs start blinking.")
if len(sys.argv) == 1:
addr, name = wiimote.find()[0]
elif len(sys.argv) == 2:
addr = sys.argv[1]
name = None
elif len(sys.argv) == 3:
addr, name = sys.argv[1:3]
print(("Connecting to %s (%s)" % (name, addr)))
wm = wiimote.connect(addr, name)
# Demo Time!
patterns = [[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
[0, 0, 1, 0],
[0, 1, 0, 0],
[1, 0, 0, 0]]
for i in range(5):
for p in patterns:
wm.leds = p
time.sleep(0.05)
def print_ir(ir_data):
if len(ir_data) == 0:
return
for ir_obj in ir_data:
# print("%4d %4d %2d " % (ir_obj["x"],ir_obj["y"],ir_obj["size"]), end=' ')
print("%4d %4d %2d " % (ir_obj["x"], ir_obj["y"], ir_obj["size"]))
print()
#wm.ir.register_callback(print_ir)
while True:
if wm.buttons["A"]:
wm.leds[1] = True
wm.rumble(0.1)
print((wm.accelerometer))
elif wm.buttons["B"]:
wm.speaker.beep()
#print("beep")
else:
wm.leds[1] = False
pass
time.sleep(0.05)