from machine import Pin,PWM
import time
#define led
led_pins = [Pin(5, Pin.OUT),Pin(8, Pin.OUT),Pin(11, Pin.OUT),Pin(13, Pin.OUT)]
pwm_leds = [PWM(pin) for pin in led_pins]
#intiliaze PWM frequency
for pwm in pwm_leds:
pwm.freq(1000) #led blink for 0.0005 seconds at 50% duty
pwm.duty_u16(0) #start with led off
def set_brightness(percent):
duty = int((percent/100) * 65535) #convert to percentage to duty cycle
for pwm in pwm_leds:
pwm.duty_u16(duty)
print(f"set brightness to {percent}%")
while(1):
command = input("Enter command (off, 25, 50, 75, 100): ").strip() #get command from user input
if command == "off":
set_brightness(0) #Turn off all leds
print("All leds are off")
elif command == "25":
set_brightness(25)
elif command == "50":
set_brightness(50)
elif command == "75":
set_brightness(75)
elif command == "100":
set_brightness(100)
else:
print("Invalid command. Please use: off,25,50,75,100")