
import os, machine
from machine import Pin, SoftI2C
import ssd1306
import gfx
import time

#note: interesting lib for gfx: https://randomnerdtutorials.com/micropython-ssd1306-oled-scroll-shapes-esp32-esp8266/

# ESP8266 Oled Module Pin assignment
i2c = SoftI2C(scl=12, sda=14)

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

oled.text('Hello, World 1!', 0, 1,1) #yellow
oled.text('Hello, World 2!', 0, 17,2) #blue
oled.show()

#draw a line pixel by pixel
for x in range(oled_width + 1):
  oled.pixel(x, 29, 2)


#now use the GFX library to draw various shaped
graphics = gfx.GFX(oled_width, oled_height, oled.pixel)  
graphics.rect(5, 35, 20, 20, 2) #x , y, width, height, color
graphics.fill_triangle(30,54,50,54,40,35,2) #vertex coords, color
graphics.circle(65, 45, 10, 1) #x, y center, radius, color
graphics.line(80,54,100,34,1) #x, y start and end

oled.show()
time.sleep(2)

#scroll down whole screen
for y in range(oled_height):
    oled.scroll(0,1) #dx, dy
    oled.show()    
    
oled.text('Please reboot',0,1,1)
oled.text('to restart demo.',0,17,2)
oled.show()
