from machine import Pin, ADC
from time import sleep
# Setup 4 LED pins as output
led_pins = [Pin(16, Pin.OUT), Pin(17, Pin.OUT), Pin(18, Pin.OUT), Pin(19, Pin.OUT)]
# Setup ADC for potentiometer on GPIO 26
potentiometer = ADC(Pin(26))
while True:
# Read potentiometer value (0-65535)
pot_value = potentiometer.read_u16()
# Map pot_value to delay range (0.05 to 1.0 seconds)
delay = pot_value / 65535 * (1.0 - 0.05) + 0.05
# Turn ON LED 1 and LED 2, Turn OFF LED 3 and LED 4
led_pins[0].value(1)
led_pins[1].value(1)
led_pins[2].value(0)
led_pins[3].value(0)
# Wait for the mapped delay
sleep(delay)
# Turn OFF LED 1 and LED 2, Turn ON LED 3 and LED 4
led_pins[0].value(0)
led_pins[1].value(0)
led_pins[2].value(1)
led_pins[3].value(1)
# Wait for the mapped delay
sleep(delay)
# Print the potentiometer value and LED delay for debugging
print(f"Potentiometer Value: {pot_value}, LED Delay: {delay:.2f} s")