#based on a randomnerdtutorial - fixed

from machine import Pin, I2C, ADC
import ssd1306
from time import sleep

# ESP32 Pin assignment 
i2c = I2C(0, scl=Pin(22), sda=Pin(21))

pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB)        #Full range 3,3V (Wert 0 bis 4.095)

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)


# simulation initialisierung

print("boot up...")
oled.fill(0)
oled.text("Booting", 0, 5)
oled.show()
sleep(1)
oled.text(" up...", 0, 15)
oled.show()
sleep(0.5)
oled.fill(0) #clears the screen
sleep(0.5)
oled.text("     READY", 0, 25)
oled.show()
  
while True:
  pot_value = pot.read()
  print(pot_value)
  converted_val = str(pot_value) # Zum Anzeigen muss Wert in String kovertiert werden
  oled.fill(0)
  oled.text("Value: " + converted_val, 0, 25)
  oled.show()
  sleep(0.1)