import time
from machine import SoftI2C,Pin,PWM,ADC
from pico_i2c_lcd import I2cLcd
# led = Pin(0,Pin.OUT)
# led.on()
# time.sleep(1)
# led.off()
# print("Hello, Pi Pico!")
i2c = SoftI2C(sda=Pin(26),scl=Pin(21),freq=400000)
lcd = I2cLcd(i2c,i2c.scan()[0],2,16)
pot = ADC(28)
def perc_to_hex(n):
return int(n/100*65535);
def freq_change_buzzer(l,r):
pot_val = pot.read_u16()
percent = int(pot_val/65535*100)
fre = l + int(percent*(r-l)/100)
load = PWM(Pin(0))
load.freq(fre)
load.duty_u16(perc_to_hex(25))
lcd.putstr("Freq: "+str(fre)+" percent: "+str(percent)+"%")
time.sleep(1)
lcd.clear()
def voltage_change_bulb():
pot_val = pot.read_u16()
volt = round((3.3/65535)*pot_val,2)
percent = int(pot_val/65535*100)
load = PWM(Pin(0))
load.freq(1000)
load.duty_u16(pot_val)
lcd.putstr("Volt: "+str(volt)+" percent: "+str(percent)+"%")
time.sleep(1)
lcd.clear()
while True:
freq_change_buzzer(2000,4000)
while True:
voltage_change_bulb()