/
code.py
125 lines (107 loc) · 3.04 KB
/
code.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
# SPDX-FileCopyrightText: 2020 Eva Herrada for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Based on code written by @DavidGlaude on Twitter
# https://twitter.com/DavidGlaude/status/1340365817138044933
# https://gist.github.com/dglaude/4bf8d0a13c9c8ca8b05d6c0e9176bd20
import time
import alarm
import displayio
import board
import adafruit_imageload
from adafruit_display_shapes.rect import Rect
from adafruit_magtag.magtag import Graphics
from digitalio import DigitalInOut, Direction, Pull
projects = [
"weather",
"spacex",
"covid",
"showerthoughts",
"tides",
"year",
"showtimes",
"slideshow",
]
btnA = DigitalInOut(board.D15)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP
btnB = DigitalInOut(board.D14)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP
btnD = DigitalInOut(board.D11)
btnD.direction = Direction.INPUT
btnD.pull = Pull.UP
graphics = Graphics(auto_refresh=False)
display = graphics.display
group = displayio.Group()
selector = False
if not btnA.value or not btnB.value or not btnC.value or not btnD.value:
selector = True
if selector:
background = Rect(0, 0, 296, 128, fill=0xFFFFFF)
group.append(background)
for i in range(8):
sprite_sheet, palette = adafruit_imageload.load(
f"/bmps/{projects[i]}.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette,
)
sprite = displayio.TileGrid(
sprite_sheet,
pixel_shader=palette,
width=1,
height=1,
tile_width=62,
tile_height=54,
x=6 + 74 * (i % 4),
y=6 + 62 * (i // 4),
)
group.append(sprite)
rect = Rect(4, 4, 66, 58, outline=0x000000, stroke=2)
group.append(rect)
display.root_group = group
display.refresh()
time.sleep(5)
print("Ready")
selected = 0
while True:
if not btnA.value and not btnD.value:
alarm.sleep_memory[0] = selected
break
if not btnA.value and selected != 0 and selected != 4:
selected -= 1
rect.x -= 74
display.refresh()
print("left")
time.sleep(5)
continue
if not btnB.value and selected > 3:
selected -= 4
rect.y -= 62
display.refresh()
print("up")
time.sleep(5)
continue
if not btnC.value and selected < 4:
selected += 4
rect.y += 62
display.refresh()
print("down")
time.sleep(5)
continue
if not btnD.value and selected != 3 and selected != 7:
selected += 1
rect.x += 74
display.refresh()
print("right")
time.sleep(5)
continue
btnA.deinit()
btnB.deinit()
btnC.deinit()
btnD.deinit()
print("Starting ", projects[int(alarm.sleep_memory[0])])
__import__("/projects/" + projects[int(alarm.sleep_memory[0])])