This commit is contained in:
bton 2024-04-12 21:20:15 +02:00
parent e80b943e3c
commit 81c8df3b67

54
oled.py
View file

@ -1,26 +1,36 @@
from luma.core.interface.serial import i2c, spi, pcf8574 Basic example of clearing and drawing pixels on a SSD1306 OLED display.
from luma.core.interface.parallel import bitbang_6800 # This example and library is meant to work with Adafruit CircuitPython API.
from luma.core.render import canvas # Author: Tony DiCola
from luma.oled.device import ssd1306 # License: Public Domain
from PIL import ImageFont
from pathlib import Path
import time
serial = i2c(port=1, address=0x3C) # Import all board pins.
device = ssd1306(serial) from board import SCL, SDA
import busio
#fonts # Import the SSD1306 module.
name_font=ImageFont.truetype("Purisa.ttf", 20) import adafruit_ssd1306
name_position=(50,0)
user_id_font=ImageFont.truetype("Purisa.ttf", 20)
user_id_position=(30,0)
def balance(user_name, balance):
with canvas(device) as draw:
pass
with canvas(device) as draw: # Create the I2C interface.
#draw.rectangle(device.bounding_box, outline="white", fill="black") i2c = busio.I2C(SCL, SDA)
draw.text(user_id_position, "1", fill="white", font=(user_id_font))
draw.text(name_position, "Test", fill="white", font=(name_font)) # Create the SSD1306 OLED class.
time.sleep(10) # The first two parameters are the pixel width and pixel height. Change these
# to the right size for your display!
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Alternatively you can change the I2C address of the device with an addr parameter:
#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31)
# Clear the display. Always call show after changing pixels to make the display
# update visible!
display.fill(0)
display.show()
# Set a pixel in the origin 0,0 position.
display.pixel(0, 0, 1)
# Set a pixel in the middle 64, 16 position.
display.pixel(64, 16, 1)
# Set a pixel in the opposite 127, 31 position.
display.pixel(127, 31, 1)
display.show()