from machine import Pin, ADC, DAC
import time
# Configure the ADC pin for the potentiometer
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_6DB) # Set attenuation to handle higher voltage range
while True:
# Read the potentiometer value (0-4095)
pot_value = pot.read()
# Map the potentiometer value (0-4095) to the DAC range (0-255)
dac_value = int(pot_value / 16) # Convert 12-bit ADC value to 8-bit DAC value
# Output the DAC value to control LED brightness
# =dac.write(dac_value)
# Print the values for debugging
print('Potentiometer Value = ', pot_value)
print('DAC Value = ', dac_value)
# Wait before updating the DAC value
time.sleep(0.1)