while True:
print(get_voltage(analog_pin))
time.sleep(0.1)
Now, rotate the potentiometer to see the values change.
Now the values range from around 0 to 3.1! Note that due to variations in each chip,
you may not get all the way to 0 or 3.1, and in some cases, you may exceed 3.1. Both
of these possibilities are normal.
The example code begins with the same imports and pin setup.
This time, you include the get_voltage helper. This function requires that you
provide an analog pin. It then maps the raw analog values, 0 to 3.1 , to the voltage
values, 0 to 3.1 . It does the math so you don't have to!
Finally, inside the loop, you provide the function with your analog_pin , and print the
resulting values.
That's all there is to reading analog voltage values using CircuitPython!
NeoPixel LED
Your board has a built-in RGB NeoPixel status LED. You can use CircuitPython code to
control the color and brightness of this LED. It is also used to indicate the bootloader
status and errors in your CircuitPython code.
©Adafruit Industries Page 137 of 263