# Basic Analog-to-Digital Converter (ADC) reading example for Raspberry Pi Pico.
# Reads analog voltage from ADC pin GP28 (ADC2) at a 50 Hz sampling rate.

from machine import ADC, Pin
import time

# Initialize ADC channel on GPIO 28 (Pico pin 34 / ADC2)
adc = ADC(Pin(28))

# Main loop continuously sampling the analog input
while True:
    # Read raw 16-bit unsigned integer value (0 to 65535, where 65535 corresponds to ~3.3V)
    adc_raw = adc.read_u16()
    
    # Print the raw ADC value to serial console (compatible with UBI Serial Plotter)
    print(adc_raw)
    
    # 20 ms delay corresponds to a 50 Hz sampling frequency
    time.sleep(0.02)