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 MixerTutorial 2 - Analog Read to Plotter'''# First we import the modules we're going to use in our codeimport timeimport boardfrom 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 valuesr_pot =AnalogIn(board.A2)whileTrue:# 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 millisecondsprint((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 MixerTutorial 2 - Analog Read to Plotter'''import timeimport boardfrom analogio import AnalogInr_pot =AnalogIn(board.A2)whileTrue:print((r_pot.value,)) time.sleep(0.1)