from machine import Pin, PWM, ADC
# Initialize PWM and ADC
pwm = PWM(Pin(15))
adc = ADC(Pin(28))
# Initialize Push Buttons
button_on = Pin(14, Pin.IN, Pin.PULL_UP) # Assuming the "on" button is connected to pin 14
button_off = Pin(13, Pin.IN, Pin.PULL_UP) # Assuming the "off" button is connected to pin 13
# Set PWM Frequency
pwm.freq(1000)
# LED state variable
led_on = False
while True:
# Read ADC value
duty = adc.read_u16()
pwm.duty_u16(duty)
# Check push button state for turning the LED on
if button_on.value() == 0: # Assuming 0 means the button is pressed
led_on = True
pwm.duty_u16(65535) # Set maximum duty cycle for full brightness
# Check push button state for turning the LED off
if button_off.value() == 0: # Assuming 0 means the button is pressed
led_on = False
pwm.duty_u16(0) # Turn off the LED