Skip to content

Commit 2e8b236

Browse files
committed
updated code and sprites
1 parent 4ae722b commit 2e8b236

7 files changed

+29
-8
lines changed

LCARS/bmps/1_lcars_anim_sheet.bmp

24.1 KB
Binary file not shown.

LCARS/bmps/2_lcars_white.bmp

4.06 KB
Binary file not shown.

LCARS/bmps/3_lcars_black.bmp

4.06 KB
Binary file not shown.
-24.1 KB
Binary file not shown.
-4.06 KB
Binary file not shown.
-1.06 KB
Binary file not shown.

LCARS/code.py

100644100755
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22
#
33
# SPDX-License-Identifier: MIT
44
# LCARS MatrixPortal Display
5+
# LED brigthness code by Jan Goolsbey
56

67
import time
78
import os
89
import board
910
import displayio
1011
from digitalio import DigitalInOut, Pull
12+
from simpleio import map_range # For color brightness calculation
1113
from adafruit_matrixportal.matrix import Matrix
1214
from adafruit_debouncer import Debouncer
1315

16+
import supervisor
17+
supervisor.runtime.autoreload = True
18+
1419
SPRITESHEET_FOLDER = "/bmps"
1520
DEFAULT_FRAME_DURATION = 0.7 # 100ms
1621
AUTO_ADVANCE_LOOPS = 3
22+
bitmap = ""
23+
brightness = 15 # ### Integer value from 0 to 15
1724

1825
# --- Display setup ---
19-
matrix = Matrix(bit_depth=1, width=128, height=64)
26+
matrix = Matrix(bit_depth=4, width=128, height=64)
2027
sprite_group = displayio.Group()
2128
matrix.display.show(sprite_group)
2229

@@ -47,19 +54,28 @@
4754
frame_count = 0
4855
frame_duration = DEFAULT_FRAME_DURATION
4956

57+
def image_brightness(new_bright=0):
58+
"""Calculate the white color brightness.
59+
Returns a white RBG888 color value proportional to `new_bright`."""
60+
# Scale brightness value
61+
bright = int(map_range(new_bright, 0, 15, 0x00, 0xFF))
62+
# Recombine and return a composite RGB888 value
63+
return (bright << 16) + (bright << 8) + bright
5064

5165
def load_image():
5266
"""
5367
Load an image as a sprite
5468
"""
5569
# pylint: disable=global-statement
56-
global current_frame, current_loop, frame_count, frame_duration
70+
global current_frame, current_loop, frame_count, frame_duration, bitmap
5771
while sprite_group:
5872
sprite_group.pop()
5973

6074
filename = SPRITESHEET_FOLDER + "/" + file_list[current_image]
6175

6276
bitmap = displayio.OnDiskBitmap(filename)
77+
### Change the palette value proportional to BRIGHTNESS
78+
bitmap.pixel_shader[1] = image_brightness(brightness)
6379
sprite = displayio.TileGrid(
6480
bitmap,
6581
pixel_shader=bitmap.pixel_shader,
@@ -102,14 +118,19 @@ def advance_frame():
102118

103119
advance_image()
104120

121+
last_time = time.monotonic()
122+
123+
105124
while True:
106125
button_down.update()
107126
button_up.update()
108127
if button_up.fell:
109-
print("up fell")
110-
auto_advance = not auto_advance
111-
if button_down.fell:
112-
print("down fell")
113128
advance_image()
114-
advance_frame()
115-
time.sleep(frame_duration)
129+
if button_down.fell:
130+
brightness = (brightness + 2) % 16
131+
print(brightness)
132+
bitmap.pixel_shader[1] = image_brightness(brightness) # ### Change the brightness
133+
134+
if time.monotonic() - last_time > frame_duration:
135+
advance_frame()
136+
last_time = time.monotonic()

0 commit comments

Comments
 (0)