from machine import Pin, PWM, ADC
import utime
from pico_i2c_lcd import I2cLcd
from machine import I2C
i2c = I2C(id=1,scl=Pin(27),sda=Pin(26),freq=100000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
pot=ADC(Pin(28)) #ADC(2)
servo1=PWM(Pin(15))
servo1.freq(50)
while True:
utime.sleep(0.1)
valorPot=int(pot.read_u16())
valor1=int((pot.read_u16()/364)) #65535/(8191-1638)
valor=int(1638+(pot.read_u16()/10)) #65535/(8191-1638)
servo1.duty_u16(valor)
utime.sleep(0.1)
lcd.move_to(0,0)
lcd.putstr('Pot=')
lcd.move_to(5,0)
lcd.putstr(str(valorPot)+" OHM")
lcd.move_to(0,1)
lcd.putstr('Servo=')
lcd.move_to(6,1)
lcd.putstr(str(valor1)+" Grados")
print("Potenciometro= %5.2f Ohm"%valorPot, "Posición= %5.2f °"%valor1)
#escala 0--65535 a 1638 -- 8191
utime.sleep(0.1)