from machine import PWM, Pin, ADC, SoftI2C, I2C
import time
from pico_i2c_lcd import I2cLcd
i2c=SoftI2C(sda=Pin(18),scl=Pin(17),freq=400000)
lcd_addr=i2c.scan()[0]
lcd=I2cLcd(i2c,lcd_addr,2,16)
led=PWM(Pin(0))
led.freq(1000) #1000 cycles per second
#led-duty_u16(65535) #giving maximum duty cycle
x=0
#using a loop for changing the duty cycle
adc=ADC(28)
# while True:
# led.duty_u16(x)
# time.sleep(0.1)
# x+=20000
# if(x>65535):
# x=0
while True:
l=adc.read_u16()
#print(l)
n=(l/65535)*100
lcd.putstr("Duty cycle:")
lcd.putstr(str(n)[:5])
led.duty_u16(l)
time.sleep(0.1)
lcd.clear()