100 lines
3.0 KiB
Python
100 lines
3.0 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.oled.device import sh1106
|
|
from luma.core import lib
|
|
from luma.core.virtual import terminal
|
|
|
|
# load needed modules from RPi.GPIO
|
|
import RPi.GPIO as GPIO
|
|
|
|
# load needed modules from PIL
|
|
from PIL import ImageFont, ImageDraw, Image
|
|
|
|
# load more needed modules
|
|
import time
|
|
import sys
|
|
|
|
# load randommodules
|
|
from random import randint, gauss
|
|
from pathlib import Path
|
|
|
|
#GPIO define pins
|
|
RST_PIN = 25 #Reset
|
|
CS_PIN = 8
|
|
DC_PIN = 24
|
|
|
|
serial = spi(device=0, port=0, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC_PIN, gpio_RST = RST_PIN)
|
|
device = sh1106(serial, rotate=2) #sh1106
|
|
|
|
def make_font(name, size):
|
|
font_path = str(Path(__file__).resolve().parent.joinpath('fonts', name))
|
|
return ImageFont.truetype(font_path, size)
|
|
|
|
|
|
def main():
|
|
while True:
|
|
for fontname, size in [(None, None), ("tiny.ttf", 6), ("ProggyTiny.ttf", 16), ("creep.bdf", 16), ("miscfs_.ttf", 12), ("FreePixel.ttf", 12), ('ChiKareGo.ttf', 16)]:
|
|
font = make_font(fontname, size) if fontname else None
|
|
term = terminal(device, font)
|
|
|
|
term.println("Terminal mode demo")
|
|
term.println("------------------")
|
|
term.println("Uses any font to output text using a number of different print methods.")
|
|
term.println()
|
|
time.sleep(2)
|
|
term.println("The '{0}' font supports a terminal size of {1}x{2} characters.".format(fontname, term.width, term.height))
|
|
term.println()
|
|
time.sleep(2)
|
|
term.println("An animation effect is defaulted to give the appearance of spooling to a teletype device.")
|
|
term.println()
|
|
time.sleep(2)
|
|
|
|
term.println("".join(chr(i) for i in range(32, 127)))
|
|
time.sleep(2)
|
|
|
|
term.clear()
|
|
for i in range(30):
|
|
term.println("Line {0:03d}".format(i))
|
|
|
|
term.animate = False
|
|
time.sleep(2)
|
|
term.clear()
|
|
|
|
term.println("Progress bar")
|
|
term.println("------------")
|
|
for mill in range(0, 10001, 25):
|
|
term.puts("\rPercent: {0:0.1f} %".format(mill / 100.0))
|
|
term.flush()
|
|
|
|
time.sleep(2)
|
|
term.clear()
|
|
term.puts("Backspace test.")
|
|
term.flush()
|
|
time.sleep(2)
|
|
for _ in range(17):
|
|
term.backspace()
|
|
time.sleep(0.2)
|
|
|
|
time.sleep(2)
|
|
term.clear()
|
|
term.animate = True
|
|
term.println("Tabs test")
|
|
term.println("|...|...|...|...|...|")
|
|
term.println("1\t2\t4\t11")
|
|
term.println("992\t43\t9\t12")
|
|
term.println("\t3\t99\t1")
|
|
term.flush()
|
|
time.sleep(2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
GPIO.cleanup() |