from machine import Pin, PWM
from utime import sleep
# Define LED pins and initialize PWM for each pin
led_pins = [1, 5, 9, 13]
leds = [PWM(Pin(pin), freq=1000) for pin in led_pins]
# Main loop to accept user input and control LED brightness
while True:
s = input("command:") # Get input from user
if s == "off":
# Set all LEDs to 0% brightness (off)
for led in leds:
led.duty_u16(0)
elif s == "25":
# Set all LEDs to 25% brightness
for led in leds:
led.duty_u16(int(0.25 * 65535))
elif s == "50":
# Set all LEDs to 50% brightness
for led in leds:
led.duty_u16(int(0.5 * 65535))
elif s == "75":
# Set all LEDs to 75% brightness
for led in leds:
led.duty_u16(int(0.75 * 65535))
elif s == "100":
# Set all LEDs to 100% brightness
for led in leds:
led.duty_u16(65535)
else:
print("Invalid command. Please enter 'off', '25', '50', '75', or '100'.")