AnalogRead__ - jimaobian/DFRobotWikiCn GitHub Wiki

int analogRead (uint8_t pin)

读模拟引脚

读模拟引脚, 返回[0-1023]之间的值. 每读一次需要花1微妙的时间.

参数:

  • pin 引脚编号

返回:

  • 0到1023之间的值

例子:

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read

void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}