This repository has been archived on 2022-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
zeropod/graphics.py

38 lines
963 B
Python
Raw Normal View History

2022-04-23 13:37:54 -05:00
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
2022-04-23 18:25:09 -05:00
CHAR_WIDTH = 6
2022-04-23 13:37:54 -05:00
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):
2022-04-23 18:25:09 -05:00
self._display.text(text, x * self.CHAR_WIDTH, y * self.LINE_HEIGHT, c)
2022-04-23 13:37:54 -05:00
def pixel(self, x, y, c = None):
return self._display.pixel(x, y, c)
2022-04-24 10:07:39 -05:00
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)
2022-04-23 13:37:54 -05:00
def show(self):
self._display.show()