-
Notifications
You must be signed in to change notification settings - Fork 0
/
joystick.py
89 lines (81 loc) · 3.28 KB
/
joystick.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
import RPi.GPIO as GPIO
import unicornhat as UH
import time
def paintLEDs(patternToPaint):
for y in range(8):
for x in range(8):
r = patternToPaint[y][x] * 255
UH.set_pixel(x, y, r, 0, 0)
UH.show()
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
right_button = GPIO.input(19)
left_button = GPIO.input(6)
up_button = GPIO.input(5)
down_button = GPIO.input(13)
if right_button == False:
print "5"
if left_button == False:
print "6"
if up_button == False:
print "19"
if down_button == False:
print "13"
patternToPaint = [[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0 ]
]
if right_button == False:
print "RIGHT"
patternToPaint = [[ 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 1, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 1, 0, 0 ],
[ 0, 1, 1, 1, 1, 1, 1, 0 ],
[ 0, 1, 1, 1,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