-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.py
More file actions
53 lines (42 loc) · 1.22 KB
/
Copy pathcode.py
File metadata and controls
53 lines (42 loc) · 1.22 KB
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
import board
import digitalio
import displayio
import neopixel_write
import sys
import terminalio
from adafruit_display_text import label, wrap_text_to_pixels
SCALE = 4 # Scale factor for text size
display = board.DISPLAY
# Black background
bg = displayio.Bitmap(display.width, display.height, 1)
palette = displayio.Palette(1)
palette[0] = 0x000000
text_label = label.Label(
terminalio.FONT, text="",
color=0xFFFFFF, scale=SCALE, x=2, y=20,
)
root = displayio.Group()
root.append(displayio.TileGrid(bg, pixel_shader=palette))
root.append(text_label)
display.root_group = root
np_pwr = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
np_pwr.switch_to_output(True)
np_pin = digitalio.DigitalInOut(board.NEOPIXEL)
np_pin.switch_to_output()
def set_led(on):
neopixel_write.neopixel_write(
np_pin, bytearray([60, 60, 60] if on else [0, 0, 0])
)
def screen_print(text):
lines = wrap_text_to_pixels(text, display.width // SCALE, terminalio.FONT)
text_label.text = "\n".join(lines)
set_led(False)
screen_print("code.py started...")
while True:
line = sys.stdin.readline().strip()
if line == "led on":
set_led(True)
elif line == "led off":
set_led(False)
else:
screen_print(line)