import utime
import machine
from machine import I2C
from LCD_API import LcdApi
from Pico_I2C_LCD import I2cLcd

I2C_ADDR     = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16

potentiometer = machine.ADC(26)
conversion_factor = 3.3 / (65535)

i2c = I2C(0, sda=machine.Pin(4), scl=machine.Pin(5), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)


lcd.clear()

lcd.move_to(5,0)
lcd.putstr("Elecrow")
lcd.move_to(3,1)
lcd.putstr("ADC:")
utime.sleep(2)

while True:
    voltage = potentiometer.read_u16() * conversion_factor
    voltage_str = "{:.2f}".format(voltage)
    lcd.move_to(8,1)
    lcd.putstr(voltage_str)
    
