# Project objectives:
# Read inputs from 3 potentiometers and display their values to the console
# Convert analog values to voltage and display them to the console
#
# Hardware and connections used:
# Potentiometer SIG pins to GPIO Pins 26, 27, and 28 (capable of ADC)
#
# Programmer: Adrian Josele G. Quional
# modules
from machine import Pin, ADC
from time import sleep
# Create ADC objects for each potentiometer, specifying the GPIO pins for their SIG pins
pot_adc1 = ADC(Pin(26))
pot_adc2 = ADC(Pin(27))
pot_adc3 = ADC(Pin(28))
# Continuously read data from the potentiometers and display the values to the console
while True:
# Read analog values from the potentiometers
analog_value1 = pot_adc1.read_u16()
analog_value2 = pot_adc2.read_u16()
analog_value3 = pot_adc3.read_u16()
# Convert analog values to voltage
voltage1 = analog_value1 * (3.3 / 65535)
voltage2 = analog_value2 * (3.3 / 65535)
voltage3 = analog_value3 * (3.3 / 65535)
# Display the values for all three potentiometers
print(f"Potentiometer 1 - Analog value: {analog_value1}, Voltage: {voltage1}V")
print(f"Potentiometer 2 - Analog value: {analog_value2}, Voltage: {voltage2}V")
print(f"Potentiometer 3 - Analog value: {analog_value3}, Voltage: {voltage3}V")
print("==========")
sleep(1)