-
Notifications
You must be signed in to change notification settings - Fork 0
/
i75_lines.py
173 lines (146 loc) · 4.75 KB
/
i75_lines.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# pylint: disable=line-too-long,import-error,unused-import,too-many-locals,invalid-name,unused-variable,too-many-statements,invalid-envvar-default
"""
mp_lines.py
a rainbow of lines
"""
import time
import os
import sys
import board
import busio
import displayio
import framebufferio
import rgbmatrix
import terminalio
from rainbowio import colorwheel
from digitalio import DigitalInOut
import neopixel
import adafruit_ds3231 # RTC
import adafruit_fancyled.adafruit_fancyled as fancy
from led_panel import LedPanel
# try:
# from _secrets import af_secrets as secrets
# except ImportError:
# print("WiFi secrets are kept in secrets.py, please add them there!")
# raise
def compatibility_check():
"""
basic checks to make sure the board and version are correct
"""
board_type = os.uname().machine
if "Pimoroni Interstate 75" not in board_type:
print(f"unsupported board type: {board_type}")
print("this code is designed to run on Pimoroni Interstate 75")
sys.exit(1)
cp_info = sys.implementation
if cp_info.version[0] < 8:
print(f"unsupported CircuitPython major version: {cp_info.version[0]}")
print("this code is designed to run on CircuitPython 8.0 or later")
sys.exit(1)
def make_palette_rgb():
"""
build a rainbow palette
of gamma-corrected values
this should probably be a class
so it can go in a separate file
"""
palette = [None] * 48
# red to orange
palette[0] = (255, 0, 0)
palette[1] = (255, 56, 0)
palette[2] = (255, 81, 0)
palette[3] = (255, 102, 0)
palette[4] = (255, 119, 0)
palette[5] = (255, 136, 0)
palette[6] = (255, 151, 0)
palette[7] = (255, 165, 0)
# orange to yellow
palette[8] = (255, 165, 0)
palette[9] = (255, 177, 0)
palette[10] = (255, 190, 0)
palette[11] = (255, 203, 0)
palette[12] = (255, 216, 0)
palette[13] = (255, 229, 0)
palette[14] = (255, 242, 0)
palette[15] = (255, 255, 0)
# yellow to green
palette[16] = (255, 255, 0)
palette[17] = (235, 255, 0)
palette[18] = (213, 255, 0)
palette[19] = (190, 255, 0)
palette[20] = (164, 255, 0)
palette[21] = (133, 255, 0)
palette[22] = (94, 255, 0)
palette[23] = (0, 255, 0)
# green to blue
palette[24] = (0, 255, 0)
palette[25] = (0, 240, 115)
palette[26] = (0, 220, 192)
palette[27] = (0, 198, 255)
palette[28] = (0, 174, 255)
palette[29] = (0, 144, 255)
palette[30] = (0, 102, 255)
palette[31] = (0, 0, 255)
# blue to purple
palette[32] = (0, 0, 255)
palette[33] = (63, 0, 253)
palette[34] = (89, 0, 250)
palette[35] = (108, 3, 248)
palette[36] = (123, 10, 246)
palette[37] = (137, 17, 244)
palette[38] = (149, 25, 242)
palette[39] = (160, 32, 240)
# purple to red
palette[40] = (160, 32, 240)
palette[41] = (205, 0, 211)
palette[42] = (236, 0, 179)
palette[43] = (255, 0, 145)
palette[44] = (255, 0, 112)
palette[45] = (255, 0, 79)
palette[46] = (255, 0, 47)
palette[47] = (255, 0, 0)
for i in range(len(palette)):
r, g, b = palette[i]
gc = fancy.gamma_adjust(fancy.CRGB(r, g, b), gamma_value=1.8)
palette[i] = gc.pack()
gamma_palette = displayio.Palette(48)
for i in range(len(gamma_palette)):
gamma_palette[i] = palette[i]
return gamma_palette
def main():
"""
they call it main.
"""
# is it safe
compatibility_check()
# get rid of any pre-existing display
displayio.release_displays()
panel = LedPanel()
panel_auto_refresh = (os.getenv("panel_auto_refresh") == "True", "True") # or False if refreshing the display manually
display = framebufferio.FramebufferDisplay(panel.matrix, auto_refresh=panel_auto_refresh)
master_group = displayio.Group()
display.show(master_group)
i2c = board.I2C() # read for accelerometer and RTC
# RTC - https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout/circuitpython
ds3231 = adafruit_ds3231.DS3231(i2c)
current_time = ds3231.datetime # struct_time
bitmap = [None] * panel.matrix.width
tile_grid = [None] * panel.matrix.width
palette = make_palette_rgb()
for i in range(0, panel.matrix.width):
bitmap[i] = displayio.Bitmap(1, panel.matrix.height, 48)
for x in range(0, panel.matrix.height):
bitmap[i][0,x] = i
tile_grid[i] = displayio.TileGrid(bitmap[i], pixel_shader=palette)
tile_grid[i].x = i
master_group.append(tile_grid[i])
i = 0
while True:
i += 1
if i > 47:
i = 0
for x in range(0, panel.matrix.height):
for y in range(0, panel.matrix.width):
bitmap[y][x] = i
if __name__ == "__main__":
main()