This code shows how you can read data from a potentiometer and send it to the computer, where you can see it appear in the serial console and plotter in Mu.
'''
Pico Slice 1 - RGB Mixer
Tutorial 2 - Analog Read to Plotter
'''
# First we import the modules we're going to use in our code
import time
import board
from analogio import AnalogIn
# We'll represent the potentiometer in code as an AnalogIn object
# This makes it very easy to use the ADC to convert analog voltages to digital values
r_pot = AnalogIn(board.A2)
while True: # Loop Forever:
analog_val = r_pot.value # Read the analog value from r_pot's value attribute
plotter_data = (analog_val,) # The plotter expects Tuples (32,45,-21) and this is how we create 1 value tuple
print(plotter_data) # Send tuple to the computer over USB, it'll automatically show up in the Serial and Chart
time.sleep(0.1) # Do nothing for 100 milliseconds
print((r_pot.value,)) # Do the same thing as above, but in a single line of code
time.sleep(0.1)
Just Code
'''
Pico Slice 1 - RGB Mixer
Tutorial 2 - Analog Read to Plotter
'''
import time
import board
from analogio import AnalogIn
r_pot = AnalogIn(board.A2)
while True:
print((r_pot.value,))
time.sleep(0.1)