from machine import ADC, Pin
import time
# 1. Initialize ADC on GPIO 4
pot = ADC(Pin(4))
# 2. Set Attenuation for 3.3V range
# ATTN_11DB allows measuring from 0V to approx 3.1V - 3.3V
pot.atten(ADC.ATTN_11DB)
print("Starting ADC Simulation...")
while True:
# Read raw 16-bit value (0-65535)
raw_value = pot.read_u16()
# Convert to Voltage
# 65535 is the max value for u16
voltage = (raw_value / 65535) * 3.3
# Print results
print(f"Raw: {raw_value:5d} | Voltage: {voltage:.2f} V")
time.sleep(0.1)