import machine
import utime
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import gfx
from picozero import LED



red0 = LED(19)
red1 = LED(20)
red2 = LED(21)
red3 = LED(18)
pot_l = machine.ADC(27)
pot_r = machine.ADC(26)
pot_size = machine.ADC(28)
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128,64,i2c)
graphics = gfx.GFX(128, 64, oled.pixel)
button = Pin(14, Pin.IN, Pin.PULL_UP)
button1 = Pin(15, Pin.IN, Pin.PULL_UP)
is_inverted = False
def toggle_display_state(pin):
    global is_inverted
    is_inverted = not is_inverted
    if is_inverted:
        oled.invert(1)  # Invert the display
        print("black on blue")
    else:
       oled.invert(0)  # Set back to normal
       oled.show()
       print("blue on black")  # Update the display


button1.irq(trigger=Pin.IRQ_FALLING, handler=toggle_display_state)

# oled.invert(True)

while True:
    red0.pulse(fade_in_time=2, fade_out_time=2)
    red1.pulse(fade_in_time=3, fade_out_time=3)
    red2.pulse(fade_in_time=4, fade_out_time=4)    
    rawH = pot_l.read_u16()
    rawV = pot_r.read_u16()
    rawS = pot_size.read_u16()
    print(rawV, rawH, rawS)
    utime.sleep_ms(25)
    horPixel = round(((rawH-200)/512),0)
    cursor = round((rawS/8192),0)
    vertPixel = round((rawV/1024),0)
    print("x =",horPixel, "y =",vertPixel, "c =", cursor)
    x = int(horPixel)
    y = int(vertPixel)
    c = int(cursor)
   # oled.pixel(x,y,1)
    #oled.fill_rect(x, y, (x+1), (y+1), 1)
    graphics.fill_circle(x, y, c, 1)
    #oled.text('.', x, y, 1) 
    oled.show()
    
    if button.value() == 0:
        oled.fill(0)
        oled.show()
        print("Button Value = TRUE")
    else:
        print("Button Value = FALSE")


BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT