from machine import PWM, Pin, ADC
from time import sleep_ms
from math import pow
# Define the GPIO pins
led1_pin = 14
led2_pin = 15
pot_pin = 28
# Create the PWM objects for the LEDs and the ADC object for the potentiometer
led1 = PWM(Pin(led1_pin))
led2 = PWM(Pin(led2_pin))
pot = ADC(pot_pin)
# Set the PWM frequency to 1000 Hz
led1.freq(1000)
led2.freq(1000)
while True:
# Read the potentiometer value (0-65535)
pot_value = pot.read_u16()
# Calculate the brightness values for LED1 and LED2
led1_brightness = (16 / 65535) * pot_value
led2_brightness = 16 - led1_brightness
if led1_brightness == 16:
led2.duty_u16(0)
elif led2_brightness == 16:
led1.duty_u16(0)
# Apply the brightness values to the LEDs using an exponential scale
led1.duty_u16(int(pow(2, led1_brightness)))
led2.duty_u16(int(pow(2, led2_brightness)))
# Print the current brightness values
print(f"LED1 Brightness: {led1_brightness:.2f}%, LED2 Brightness: {led2_brightness:.2f}%")
# Delay for 100 milliseconds
sleep_ms(100)