Example-ADC

ADC: Analog Input

This Python code prints the analog value of the A0 port of the Arduino UNO board. The Arduino main control board is connected to a Windows or Linux computer, and a knob module is connected to the A0 port of the main control board.

# -*- coding: UTF-8 -*-
# Experiment effect: Print the analog value of the UNO board A0 port
# Connection: Use a Windows or Linux computer to connect to an Arduino main control board, the main control board A0 is connected to a knob module
import time
from pinpong.board import Board, Pin

Board("uno").begin()  # Initialization, select board type (uno, microbit, RPi, handpy) and port number. If no port number is entered, automatic detection will be performed
# Board("uno", "COM36").begin()  # Initialization with specified port on Windows
# Board("uno", "/dev/ttyACM0").begin()  # Initialization with specified port on Linux
# Board("uno", "/dev/cu.usbmodem14101").begin()  # Initialization with specified port on Mac

# adc0 = ADC(Pin(Pin.A0))  # Pass Pin into ADC to realize analog input  Analog input method 1
adc0 = Pin(Pin.A0, Pin.ANALOG)  # Initialize the pin for analog input Analog input method 2

while True:
  # v = adc0.read()  # Read the analog signal value of A0 port Analog input method 1
  v = adc0.read_analog()  # Read the analog signal value of A0 port Analog input method 2
  print("A0=", v)
  time.sleep(0.5)