Arduino——模擬輸入-analogRead()

Description 介紹

Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference().

 

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

從指定的模擬引腳讀取值。Arduino主板有6個通道(Mini和Nano有8個,Mega有16個),10位AD(模數)轉換器。這意味着輸入電壓0-5伏對應0-1023的整數值。這就是說讀取精度爲:5伏/1024個單位,約等於每個單位0.049伏(4.9毫伏)。輸入範圍和進度可以通過analogReference()進行修改。

 

模擬輸入的讀取週期爲100微秒(0.0001秒),所以最大讀取速度爲每秒10,000次。

 

Syntax 語法

analogRead(pin)

 

Parameters 參數

pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)

pin:讀取的模擬輸入引腳號(大多數主板是0-5,Mini和Nano是0-7,Mega是0-15)

 

Returns 返回值

int (0 to 1023)

整數型  int(0到1023)

 

Note 備註

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

如果模擬輸入引腳沒有連接到任何地方,analogRead()的返回值也會因爲某些因素而波動(如其他模擬輸入,你的手與主板靠的太近)

 

Example 例子

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
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章