Datasheet
Creating an Analog Input
analogin = AnalogIn(board.A1) Creates an object named 'analogin' which is connected to the A1 pad on the Circuit
Playground Express.
GetVoltage Helper
getVoltage(pin) is our little helper program. By default, analog readings will range from 0 (minimum) to 65535
(maximum). This helper will convert the 0-65535 reading from pin.value and convert it a 0-3.3V voltage reading.
Main Loop
The main loop is simple, it will just print out the voltage as a floating point value (the %f indicates to print as floating
point) by calling getVoltage on each of our analog object, in this case the potentiometer.
If you connect to the serial port REPL, you'll see the voltage printed out. Try turning the knob of the potentiometer to
see the voltage change!
# CircuitPlaygroundExpress_AnalogIn
# reads the analog voltage level from a 10k potentiometer
# connected to GND, 3.3V, and pin A1
# and prints the results to the REPL
import time
import board
from analogio import AnalogIn
analogin = AnalogIn(board.A1)
def getVoltage(pin): # helper
return (pin.value * 3.3) / 65536
while True:
print("Analog Voltage: %f" % getVoltage(analogin))
time.sleep(0.1)
You can use many of different kinds of external analog sensors connected to the Analog IO pads, such as
distance sensors, flex sensors, and more!!
© Adafruit Industries https://learn.adafruit.com/adafruit-circuit-playground-express Page 99 of 211










