38 lines
963 B
Python
38 lines
963 B
Python
from board import SCL, SDA
|
|
from busio import I2C
|
|
from adafruit_ssd1306 import SSD1306_I2C
|
|
|
|
class Graphics:
|
|
OLED_WIDTH = 128
|
|
OLED_HEIGHT = 64
|
|
OLED_ADDR = 0x3C
|
|
LINE_HEIGHT = 9
|
|
CHAR_WIDTH = 6
|
|
MAX_LINES = 7
|
|
|
|
def __init__(self):
|
|
i2c = I2C(SCL, SDA)
|
|
self._display = SSD1306_I2C(
|
|
self.OLED_WIDTH, self.OLED_HEIGHT, i2c, addr = self.OLED_ADDR)
|
|
|
|
def clear(self):
|
|
self._display.fill(0)
|
|
|
|
def text(self, text, x, y, c):
|
|
self._display.text(text, x * self.CHAR_WIDTH, y * self.LINE_HEIGHT, c)
|
|
|
|
def pixel(self, x, y, c = None):
|
|
return self._display.pixel(x, y, c)
|
|
|
|
def line(self, x1, y1, x2, y2, c):
|
|
self._display.line(x1, y1, x2, y2, c)
|
|
|
|
def rect(self, x1, y1, x2, y2, c):
|
|
self._display.rect(x1, y1, x2, y2, c)
|
|
|
|
def fill_rect(self, x1, y1, x2, y2, c):
|
|
self._display.fill_rect(x1, y1, x2, y2, c)
|
|
|
|
def show(self):
|
|
self._display.show()
|