Create code-fast.py
This commit is contained in:
parent
49fa3c2641
commit
805202de6b
1 changed files with 38 additions and 0 deletions
38
CircuitPython_gifio/Single/code-fast.py
Normal file
38
CircuitPython_gifio/Single/code-fast.py
Normal 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)
|
||||
Loading…
Reference in a new issue