from ssd1306 import SSD1306_I2C
from machine import Pin, I2C, Timer
from time import sleep

i2c = I2C(1, scl=Pin(7), sda=Pin(6), freq=200000)
oled = SSD1306_I2C(128, 64, i2c)

# Copied from: https://gitlab.cba.mit.edu/quentinbolsee/qpad-xiao/-/blob/main/code/Micropython/hello_qed.py
def drawLine(x0, y0, x1, y1, c=1):
  dx = abs(x1 - x0)
  sx = 1 if x0 < x1 else -1
  dy = -abs(y1 - y0)
  sy = 1 if y0 < y1 else -1
  err = dx + dy
  while True:
      if 0 <= x0 < 128 and 0 <= y0 < 64:
          oled.pixel(x0, y0, c)
      if x0 == x1 and y0 == y1:
          break
      e2 = err * 2
      if e2 >= dy:
          err += dy
          x0 += sx
      if e2 <= dx:
          err += dx
          y0 += sy

oled.fill(1)
drawLine(0, 0, 128, 64, 0)
drawLine(0, 64, 128, 0, 0)
oled.show()
