updated code and sprites

This commit is contained in:
John Park 2023-05-03 07:38:31 -07:00
parent 4ae722bca3
commit 2e8b236de3
7 changed files with 29 additions and 8 deletions

BIN
LCARS/bmps/1_lcars_anim_sheet.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
LCARS/bmps/2_lcars_white.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
LCARS/bmps/3_lcars_black.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

37
LCARS/code.py Normal file → Executable file
View file

@ -2,21 +2,28 @@
#
# SPDX-License-Identifier: MIT
# LCARS MatrixPortal Display
# LED brigthness code by Jan Goolsbey
import time
import os
import board
import displayio
from digitalio import DigitalInOut, Pull
from simpleio import map_range # For color brightness calculation
from adafruit_matrixportal.matrix import Matrix
from adafruit_debouncer import Debouncer
import supervisor
supervisor.runtime.autoreload = True
SPRITESHEET_FOLDER = "/bmps"
DEFAULT_FRAME_DURATION = 0.7 # 100ms
AUTO_ADVANCE_LOOPS = 3
bitmap = ""
brightness = 15 # ### Integer value from 0 to 15
# --- Display setup ---
matrix = Matrix(bit_depth=1, width=128, height=64)
matrix = Matrix(bit_depth=4, width=128, height=64)
sprite_group = displayio.Group()
matrix.display.show(sprite_group)
@ -47,19 +54,28 @@ current_loop = 0
frame_count = 0
frame_duration = DEFAULT_FRAME_DURATION
def image_brightness(new_bright=0):
"""Calculate the white color brightness.
Returns a white RBG888 color value proportional to `new_bright`."""
# Scale brightness value
bright = int(map_range(new_bright, 0, 15, 0x00, 0xFF))
# Recombine and return a composite RGB888 value
return (bright << 16) + (bright << 8) + bright
def load_image():
"""
Load an image as a sprite
"""
# pylint: disable=global-statement
global current_frame, current_loop, frame_count, frame_duration
global current_frame, current_loop, frame_count, frame_duration, bitmap
while sprite_group:
sprite_group.pop()
filename = SPRITESHEET_FOLDER + "/" + file_list[current_image]
bitmap = displayio.OnDiskBitmap(filename)
### Change the palette value proportional to BRIGHTNESS
bitmap.pixel_shader[1] = image_brightness(brightness)
sprite = displayio.TileGrid(
bitmap,
pixel_shader=bitmap.pixel_shader,
@ -102,14 +118,19 @@ def advance_frame():
advance_image()
last_time = time.monotonic()
while True:
button_down.update()
button_up.update()
if button_up.fell:
print("up fell")
auto_advance = not auto_advance
if button_down.fell:
print("down fell")
advance_image()
advance_frame()
time.sleep(frame_duration)
if button_down.fell:
brightness = (brightness + 2) % 16
print(brightness)
bitmap.pixel_shader[1] = image_brightness(brightness) # ### Change the brightness
if time.monotonic() - last_time > frame_duration:
advance_frame()
last_time = time.monotonic()