Add display/screen.py

This commit is contained in:
Xargana 2025-05-16 15:40:21 +02:00
parent 3ac5417b1a
commit d84a5e8db5

21
display/screen.py Normal file
View file

@ -0,0 +1,21 @@
import board
import busio
import adafruit_ssd1306
from PIL import Image, ImageDraw
class OLEDDisplay:
def __init__(self, width=128, height=64):
i2c = busio.I2C(board.SCL, board.SDA)
self.display = adafruit_ssd1306.SSD1306_I2C(width, height, i2c)
self.image = Image.new("1", (width, height))
self.draw = ImageDraw.Draw(self.image)
self.clear()
def clear(self):
self.draw.rectangle((0, 0, self.display.width, self.display.height), outline=0, fill=0)
self.display.image(self.image)
self.display.show()
def show_image(self):
self.display.image(self.image)
self.display.show()