diff --git a/LCARS/bmps/1_lcars_anim_sheet.bmp b/LCARS/bmps/1_lcars_anim_sheet.bmp new file mode 100755 index 000000000..0b0be2c8f Binary files /dev/null and b/LCARS/bmps/1_lcars_anim_sheet.bmp differ diff --git a/LCARS/bmps/2_lcars_white.bmp b/LCARS/bmps/2_lcars_white.bmp new file mode 100755 index 000000000..f8c7613c4 Binary files /dev/null and b/LCARS/bmps/2_lcars_white.bmp differ diff --git a/LCARS/bmps/3_lcars_black.bmp b/LCARS/bmps/3_lcars_black.bmp new file mode 100755 index 000000000..8f07bf8fb Binary files /dev/null and b/LCARS/bmps/3_lcars_black.bmp differ diff --git a/LCARS/bmps/lcarswhite_128_x_64_sheet.bmp b/LCARS/bmps/lcarswhite_128_x_64_sheet.bmp deleted file mode 100644 index 6dd8000d3..000000000 Binary files a/LCARS/bmps/lcarswhite_128_x_64_sheet.bmp and /dev/null differ diff --git a/LCARS/bmps/lcarswhite_128_x_64_still.bmp b/LCARS/bmps/lcarswhite_128_x_64_still.bmp deleted file mode 100644 index c11da4a5c..000000000 Binary files a/LCARS/bmps/lcarswhite_128_x_64_still.bmp and /dev/null differ diff --git a/LCARS/bmps/lcarswhite_128_x_64_still_dim.bmp b/LCARS/bmps/lcarswhite_128_x_64_still_dim.bmp deleted file mode 100644 index 9bdbc540c..000000000 Binary files a/LCARS/bmps/lcarswhite_128_x_64_still_dim.bmp and /dev/null differ diff --git a/LCARS/code.py b/LCARS/code.py old mode 100644 new mode 100755 index f6b79d108..6102bb1c7 --- a/LCARS/code.py +++ b/LCARS/code.py @@ -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()