from machine import Pin, ADC, PWM
from time import sleep
# Setup LEDs with updated pins
led1 = Pin(0, Pin.OUT) # Red LED at GPIO 0
led2 = Pin(6, Pin.OUT) # Yellow LED at GPIO 6 (Updated)
led3 = Pin(12, Pin.OUT) # Green LED at GPIO 12 (Updated)
# Setup Buzzer and Potentiometer
buz = PWM(Pin(2)) # Buzzer at GPIO 2
buz.freq(500) # Set frequency to 500Hz
pot = ADC(26) # Potentiometer at ADC 26
while True:
val = pot.read_u16() # Read value from potentiometer
# Reset all components to off/silent state at start of loop
led1.off()
led2.off()
led3.off()
buz.duty_u16(0) # Turn off buzzer sound
# Check potentiometer value ranges
if val < 21845:
led1.on()
buz.duty_u16(30000) # Turn on buzzer (approx 50% volume)
elif val < 43690:
led2.on()
# Buzzer remains off here based on your original code
else:
led3.on()
# Buzzer remains off here based on your original code
sleep(0.1)