Create code-fast.py

This commit is contained in:
Anne Barela 2023-03-29 15:47:34 -04:00 committed by GitHub
parent 49fa3c2641
commit 805202de6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2023 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#
# Play a single animated GIF file (display_bus method)
#
# Documentation:
# https://docs.circuitpython.org/en/latest/shared-bindings/gifio/
# Updated 3/29/2023
import board
import struct
import gifio
import time
display = board.DISPLAY
# Take over display to drive directly
display.auto_refresh = False
display_bus = display.bus
try:
odg = gifio.OnDiskGif('/sample.gif')
except OSError: # pylint: disable=broad-except
raise Exception("sample.gif was not found\n")
start = time.monotonic()
next_delay = odg.next_frame() # Load the first frame
end = time.monotonic()
overhead = end - start
# Display repeatedly & directly.
while True:
# Sleep for the frame delay specified by the GIF,
# minus the overhead measured to advance between frames.
time.sleep(max(0, next_delay - overhead))
next_delay = odg.next_frame()
display_bus.send(42, struct.pack(">hh", 0, odg.bitmap.width - 1))
display_bus.send(43, struct.pack(">hh", 0, odg.bitmap.height - 1))
display_bus.send(44, odg.bitmap)