analogRead()

Description

Reads the value from the specified analog pin. The 86Duino boards contain several channels (6 channels on the Zero and EduCake, 7 on the One), 11-bit analog to digital converter. This means that it will map input voltages between 0 and 3.3 volts into integer values between 0 and 1023 (or 2047 by calling analogReadResolution() to set the 11-bit resolution). This yields a resolution between readings of: 3.3 volts / 1024 units or, .0032 volts (3.2 mV) per unit.

It takes about 15 microseconds (0.000015 s) to read an analog input, so the maximum reading rate is about 66,666 times a second.

In addition, there is no any analog pin on 86Duino PLC, the value getting from analogRead() is not available.

 

Syntax
analogRead(pin)

 

Parameters

pin: the number of the analog input pin to read from (0 to 5 on the Zero and EduCake, 0 to 6 on the One)

 

Returns

int (0 to 1023 by default)

 

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.).

On 86Duino boards, the maximum input voltage of the analog to digital converter is 3.3V and so the user must take care the input voltage on every analog pin. If there is a voltage > 3.3V appearing on any analog pin, the whole analog to digital converter will behave strangely and even be destroyed.

 

Example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

int analogPin = 3;     // 可變電阻 (中間腳) 與類比pin3連接

                       // 外部接地與輸入電壓 5 伏特

int val = 0;           // 儲存讀入數值的變數

 

void setup()

{

  Serial.begin(9600);          //  設置序列埠

}

 

void loop()

{

  val = analogRead(analogPin);    // 讀取輸入 pin 腳

  Serial.println(val);            // 除錯數值

}

See also

analogReadResolution()
Tutorial: Analog Input Pins


Language Reference Home

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.