Archived
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
#! /usr/bin/python3
|
|
# -*- coding: utf8 -*-
|
|
|
|
# load needed modules from luma
|
|
from luma.core.interface.serial import i2c, spi
|
|
from luma.core.render import canvas
|
|
from luma.core import lib
|
|
|
|
from luma.oled.device import sh1106
|
|
from luma.core.sprite_system import framerate_regulator
|
|
|
|
# load needed modules from RPi.GPIO
|
|
import RPi.GPIO as GPIO
|
|
|
|
# load needed modules from PIL
|
|
from PIL import Image, ImageSequence
|
|
|
|
# load more needed modules
|
|
import time
|
|
import sys
|
|
import os
|
|
|
|
# load randommodules
|
|
#from random import randint, gauss
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
#GPIO define pins
|
|
RST_PIN = 25 #Reset
|
|
CS_PIN = 8
|
|
DC_PIN = 24
|
|
|
|
# set variables
|
|
|
|
|
|
|
|
|
|
# define display settings and create display device
|
|
serial = spi(device=0, port=0, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC_PIN, gpio_RST = RST_PIN)
|
|
device_used = sh1106(serial, rotate=2) #sh1106
|
|
|
|
# get udev context
|
|
|
|
def main():
|
|
regulator = framerate_regulator(fps=10)
|
|
img_path = str(Path(__file__).resolve().parent.joinpath('images', 'copy.gif'))
|
|
copy_gif = Image.open(img_path)
|
|
size = [min(*device_used.size)] * 2
|
|
posn = ((device_used.width - size[0]) // 2,device_used.height - size[1])
|
|
|
|
while True:
|
|
for frame in ImageSequence.Iterator(copy_gif):
|
|
with regulator:
|
|
background = Image.new("RGB", device_used.size, "white")
|
|
background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
|
|
device_used.display(background.convert(device_used.mode))
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
GPIO.cleanup() |