Skip to content

Commit f90be83

Browse files
BlitzCityDIYBlitzCityDIY
authored andcommitted
adding displayio example
1 parent 23b67ae commit f90be83

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

examples/wii_classic.bmp

75.2 KB
Binary file not shown.

examples/wii_classic.bmp.license

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import adafruit_wii_classic
6+
import terminalio
7+
import displayio
8+
import simpleio
9+
from adafruit_display_text import label
10+
from adafruit_display_shapes.circle import Circle
11+
import adafruit_ili9341
12+
13+
displayio.release_displays()
14+
15+
spi = board.SPI()
16+
tft_cs = board.A2
17+
tft_dc = board.A1
18+
19+
display_bus = displayio.FourWire(
20+
spi, command=tft_dc, chip_select=tft_cs, reset=board.A3
21+
)
22+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
23+
24+
bg = displayio.OnDiskBitmap("/wii_classic.bmp")
25+
bg_tilegrid = displayio.TileGrid(bg, pixel_shader=bg.pixel_shader)
26+
27+
# Make the display context
28+
splash = displayio.Group()
29+
splash.append(bg_tilegrid)
30+
display.show(splash)
31+
32+
i2c = board.STEMMA_I2C()
33+
ctrl_pad = adafruit_wii_classic.Wii_Classic(i2c)
34+
35+
RED = 0xFF0000
36+
BLACK = 0x000000
37+
38+
button_spots = [
39+
{"label": "dpad_up", "pos": (68, 92), "size": 7, "color": RED},
40+
{"label": "dpad_down", "pos": (68, 132), "size": 7, "color": RED},
41+
{"label": "dpad_left", "pos": (48, 112), "size": 7, "color": RED},
42+
{"label": "dpad_right", "pos": (88, 112), "size": 7, "color": RED},
43+
{"label": "button_a", "pos": (277, 111), "size": 7, "color": RED},
44+
{"label": "button_b", "pos": (253, 137), "size": 7, "color": RED},
45+
{"label": "button_x", "pos": (252, 86), "size": 7, "color": RED},
46+
{"label": "button_y", "pos": (227, 111), "size": 7, "color": RED},
47+
{"label": "button_select", "pos": (136, 116), "size": 4, "color": RED},
48+
{"label": "button_home", "pos": (160, 116), "size": 4, "color": RED},
49+
{"label": "button_start", "pos": (184, 116), "size": 4, "color": RED},
50+
{"label": "button_zl", "pos": (134, 42), "size": 12, "color": RED},
51+
{"label": "button_zr", "pos": (188, 42), "size": 12, "color": RED},
52+
{"label": "button_lshoulder", "pos": (58, 44), "size": 12, "color": RED},
53+
{"label": "button_rshoulder", "pos": (259, 44), "size": 12, "color": RED},
54+
]
55+
56+
overlays = []
57+
for spot in button_spots:
58+
b = Circle(x0=spot["pos"][0], y0=spot["pos"][1], r=spot["size"], fill=spot["color"])
59+
splash.append(b)
60+
overlays.append(b)
61+
62+
texts = [
63+
{"label": "l_x_text", "text": "L_JOY_X: 00", "x": 6, "y": 220, "color": BLACK},
64+
{"label": "l_y_text", "text": "L_JOY_Y: 00", "x": 88, "y": 220, "color": BLACK},
65+
{"label": "r_x_text", "text": "R_JOY_X: 00", "x": 173, "y": 220, "color": BLACK},
66+
{"label": "r_y_text", "text": "R_JOY_X: 00", "x": 248, "y": 220, "color": BLACK},
67+
{"label": "ls_text", "text": "L_PRESSURE: 00", "x": 10, "y": 11, "color": BLACK},
68+
{"label": "rs_text", "text": "R_PRESSURE: 00", "x": 220, "y": 11, "color": BLACK},
69+
]
70+
71+
analog_text = []
72+
for text in texts:
73+
t = label.Label(
74+
terminalio.FONT,
75+
text=text["text"],
76+
color=text["color"],
77+
x=text["x"],
78+
y=text["y"],
79+
)
80+
splash.append(t)
81+
analog_text.append(t)
82+
83+
last_l_x = 0
84+
last_r_x = 0
85+
last_l_y = 0
86+
last_r_y = 0
87+
last_r_press = 0
88+
last_l_press = 0
89+
90+
while True:
91+
l_x, l_y = ctrl_pad.joystick_l
92+
mapped_l_x = simpleio.map_range(l_x, 7, 58, -50, 50)
93+
mapped_l_y = simpleio.map_range(l_y, 7, 58, -50, 50)
94+
r_x, r_y = ctrl_pad.joystick_r
95+
mapped_r_x = simpleio.map_range(r_x, 2, 26, -50, 50)
96+
mapped_r_y = simpleio.map_range(r_y, 3, 28, -50, 50)
97+
left_pressure = ctrl_pad.l_shoulder.LEFT_FORCE
98+
right_pressure = ctrl_pad.r_shoulder.RIGHT_FORCE
99+
if last_l_x != mapped_l_x:
100+
analog_text[0].text = "L_JOY_X: %d" % mapped_l_x
101+
last_l_x = mapped_l_x
102+
if last_l_y != mapped_l_y:
103+
analog_text[1].text = "L_JOY_Y: %d" % mapped_l_y
104+
last_l_y = mapped_l_y
105+
if last_r_x != mapped_r_x:
106+
analog_text[2].text = "R_JOY_X: %d" % mapped_r_x
107+
last_r_x = mapped_r_x
108+
if last_r_y != mapped_r_y:
109+
analog_text[3].text = "R_JOY_Y: %d" % mapped_r_y
110+
last_r_y = mapped_r_y
111+
if last_r_press != right_pressure:
112+
analog_text[4].text = "R_PRESSURE: %d" % right_pressure
113+
last_r_press = right_pressure
114+
if last_l_press != left_pressure:
115+
analog_text[5].text = "L_PRESSURE: %d" % left_pressure
116+
last_l_press = left_pressure
117+
if ctrl_pad.d_pad.UP:
118+
overlays[0].fill = RED
119+
else:
120+
overlays[0].fill = BLACK
121+
if ctrl_pad.d_pad.DOWN:
122+
overlays[1].fill = RED
123+
else:
124+
overlays[1].fill = BLACK
125+
if ctrl_pad.d_pad.LEFT:
126+
overlays[2].fill = RED
127+
else:
128+
overlays[2].fill = BLACK
129+
if ctrl_pad.d_pad.RIGHT:
130+
overlays[3].fill = RED
131+
else:
132+
overlays[3].fill = BLACK
133+
if ctrl_pad.buttons.A:
134+
overlays[4].fill = RED
135+
else:
136+
overlays[4].fill = BLACK
137+
if ctrl_pad.buttons.B:
138+
overlays[5].fill = RED
139+
else:
140+
overlays[5].fill = BLACK
141+
if ctrl_pad.buttons.X:
142+
overlays[6].fill = RED
143+
else:
144+
overlays[6].fill = BLACK
145+
if ctrl_pad.buttons.Y:
146+
overlays[7].fill = RED
147+
else:
148+
overlays[7].fill = BLACK
149+
if ctrl_pad.buttons.SELECT:
150+
overlays[8].fill = RED
151+
else:
152+
overlays[8].fill = BLACK
153+
if ctrl_pad.buttons.HOME:
154+
overlays[9].fill = RED
155+
else:
156+
overlays[9].fill = BLACK
157+
if ctrl_pad.buttons.START:
158+
overlays[10].fill = RED
159+
else:
160+
overlays[10].fill = BLACK
161+
if ctrl_pad.buttons.ZL:
162+
overlays[11].fill = RED
163+
else:
164+
overlays[11].fill = BLACK
165+
if ctrl_pad.buttons.ZR:
166+
overlays[12].fill = RED
167+
else:
168+
overlays[12].fill = BLACK
169+
if ctrl_pad.buttons.L:
170+
overlays[13].fill = RED
171+
else:
172+
overlays[13].fill = BLACK
173+
if ctrl_pad.buttons.R:
174+
overlays[14].fill = RED
175+
else:
176+
overlays[14].fill = BLACK

0 commit comments

Comments
 (0)