from machine import Pin, SoftI2C
import framebuf
import ssd1306
import time


image_cards_hearts_bits = bytearray(b'\x00\x00\x00\x0088||\xfe\xfe\xff\xfe\xff\xfe\xff\xfe\x7f\xfc?\xf8\x1f\xf0\x0f\xe0\x07\xc0\x03\x80\x01\x00\x00\x00')
image_clock_solid_full_bits = bytearray(b'\x00\x1f\x00\x00\x00\xff\xe0\x00\x03\xff\xf8\x00\x07\xff\xfc\x00\x0f\xff\xfe\x00\x1f\xff\xff\x00?\xf3\xff\x00?\xf3\xff\x80\x7f\xf3\xff\x80\x7f\xf3\xff\xc0\x7f\xf3\xff\xc0\xff\xf3\xff\xc0\xff\xf3\xff\xc0\xff\xf1\xff\xc0\xff\xf8\x7f\xc0\xff\xfe?\xc0\x7f\xff\x1f\xc0\x7f\xff\xdf\xc0\x7f\xff\xff\x80?\xff\xff\x80?\xff\xff\x00\x1f\xff\xff\x00\x0f\xff\xfe\x00\x07\xff\xfc\x00\x03\xff\xf0\x00\x00\x7f\xc0\x00')

def draw():
    # Layer 1
    display.rect(0, 0, 128, 64, 1)

    # Layer 2
    display.text("HELP", 1, 2, 1)

    # cards_hearts
    fb_image_cards_hearts_bits = framebuf.FrameBuffer(image_cards_hearts_bits, 15, 16, framebuf.MONO_HLSB)
    display.blit(fb_image_cards_hearts_bits, 111, 47)

    # clock_solid_full
    fb_image_clock_solid_full_bits = framebuf.FrameBuffer(image_clock_solid_full_bits, 26, 26, framebuf.MONO_HLSB)
    display.blit(fb_image_clock_solid_full_bits, 51, 19)

    display.show()



# 3. Initialize I2C (using Software I2C for better stability on ESP32-S3 pins)
# SDA is GPIO 17, SCL is GPIO 18
scl_pin = Pin(18, Pin.OUT, pull=Pin.PULL_UP)
sda_pin = Pin(17, Pin.OUT, pull=Pin.PULL_UP)
i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=100000)

# 4. Bind the SSD1306 driver to our I2C bus (default address is 0x3C)
# Display is 128x64 pixels
display = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)

# 5. Clear and write Hello World!
draw()

print("Hello World printed to OLED successfully!")