from machine import Pin, I2C, ADC  
from time import sleep 
from esp32_i2c_lcd import I2cLcd

lcdI2C=I2C(scl=Pin(22),sda=Pin(21),freq=100000)
lcd=I2cLcd(lcdI2C,39,2,16)

led1=Pin(33,Pin.OUT)
varR=ADC(Pin(33))
varR.atten(ADC.ATTN_11DB)

while True:
  varR_value = varR.read()
  brightness = varR_value 
  led1.value(brightness)
  sleep(0.2)
  lcd.clear()
  lcd.move_to(0,0)
  lcd.putstr('ADC = '+str(varR.read()))
  lcd.move_to(0,1)
  lcd.putstr('Voltage = '+"{:.1f}".format(varR.read()*3.3/4095)+' V')
  sleep(1)
  print('ADC = ',varR.read())
  print('Voltage = ',varR.read()*3.3/4095, 'V')
  sleep(1)