first commit LCARS code and images
This commit is contained in:
parent
29e640cae0
commit
f997df68c4
4 changed files with 115 additions and 0 deletions
BIN
LCARS/bmps/lcarswhite_128_x_64_sheet.bmp
Normal file
BIN
LCARS/bmps/lcarswhite_128_x_64_sheet.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
LCARS/bmps/lcarswhite_128_x_64_still.bmp
Normal file
BIN
LCARS/bmps/lcarswhite_128_x_64_still.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
LCARS/bmps/lcarswhite_128_x_64_still_dim.bmp
Normal file
BIN
LCARS/bmps/lcarswhite_128_x_64_still_dim.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
115
LCARS/code.py
Normal file
115
LCARS/code.py
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
# SPDX-FileCopyrightText: 2023 John Park for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# LCARS MatrixPortal Display
|
||||
|
||||
import time
|
||||
import os
|
||||
import board
|
||||
import displayio
|
||||
from digitalio import DigitalInOut, Pull
|
||||
from adafruit_matrixportal.matrix import Matrix
|
||||
from adafruit_debouncer import Debouncer
|
||||
|
||||
SPRITESHEET_FOLDER = "/bmps"
|
||||
DEFAULT_FRAME_DURATION = 0.7 # 100ms
|
||||
AUTO_ADVANCE_LOOPS = 3
|
||||
|
||||
# --- Display setup ---
|
||||
matrix = Matrix(bit_depth=1, width=128, height=64)
|
||||
sprite_group = displayio.Group()
|
||||
matrix.display.show(sprite_group)
|
||||
|
||||
# --- Button setup ---
|
||||
pin_down = DigitalInOut(board.BUTTON_DOWN)
|
||||
pin_down.switch_to_input(pull=Pull.UP)
|
||||
button_down = Debouncer(pin_down)
|
||||
pin_up = DigitalInOut(board.BUTTON_UP)
|
||||
pin_up.switch_to_input(pull=Pull.UP)
|
||||
button_up = Debouncer(pin_up)
|
||||
|
||||
auto_advance = False
|
||||
|
||||
file_list = sorted(
|
||||
[
|
||||
f
|
||||
for f in os.listdir(SPRITESHEET_FOLDER)
|
||||
if (f.endswith(".bmp") and not f.startswith("."))
|
||||
]
|
||||
)
|
||||
|
||||
if len(file_list) == 0:
|
||||
raise RuntimeError("No images found")
|
||||
|
||||
current_image = None
|
||||
current_frame = 0
|
||||
current_loop = 0
|
||||
frame_count = 0
|
||||
frame_duration = DEFAULT_FRAME_DURATION
|
||||
|
||||
|
||||
def load_image():
|
||||
"""
|
||||
Load an image as a sprite
|
||||
"""
|
||||
# pylint: disable=global-statement
|
||||
global current_frame, current_loop, frame_count, frame_duration
|
||||
while sprite_group:
|
||||
sprite_group.pop()
|
||||
|
||||
filename = SPRITESHEET_FOLDER + "/" + file_list[current_image]
|
||||
|
||||
bitmap = displayio.OnDiskBitmap(filename)
|
||||
sprite = displayio.TileGrid(
|
||||
bitmap,
|
||||
pixel_shader=bitmap.pixel_shader,
|
||||
tile_width=bitmap.width,
|
||||
tile_height=matrix.display.height,
|
||||
)
|
||||
|
||||
sprite_group.append(sprite)
|
||||
|
||||
current_frame = 0
|
||||
current_loop = 0
|
||||
frame_count = int(bitmap.height / matrix.display.height)
|
||||
frame_duration = DEFAULT_FRAME_DURATION
|
||||
|
||||
|
||||
def advance_image():
|
||||
"""
|
||||
Advance to the next image in the list and loop back at the end
|
||||
"""
|
||||
# pylint: disable=global-statement
|
||||
global current_image
|
||||
if current_image is not None:
|
||||
current_image += 1
|
||||
if current_image is None or current_image >= len(file_list):
|
||||
current_image = 0
|
||||
load_image()
|
||||
|
||||
|
||||
def advance_frame():
|
||||
"""
|
||||
Advance to the next frame and loop back at the end
|
||||
"""
|
||||
# pylint: disable=global-statement
|
||||
global current_frame, current_loop
|
||||
current_frame = current_frame + 1
|
||||
if current_frame >= frame_count:
|
||||
current_frame = 0
|
||||
current_loop = current_loop + 1
|
||||
sprite_group[0][0] = current_frame
|
||||
|
||||
advance_image()
|
||||
|
||||
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)
|
||||
Loading…
Reference in a new issue