同上篇,英文部分同樣是Arduino官網頁面提供的

是Foundation部分,Microcontroller裡四個的部分的第二部分:Analog Input Pins

Foundation可參官網頁面:https://www.arduino.cc/en/Tutorial/Foundations

翻譯的部分,主要採用意譯,所以有些字詞對不起來,就是我為了語句通順稍微修改了

===========

 

Analog Input Pins   類比輸入接腳

 

  A description of the analog input pins on an Arduino chip (ATmega8, ATmega168, ATmega328P, or ATmega1280).

  在Arduino晶片(ATmega8, ATmega168, ATmega328P, or ATmega1280)上的類比輸入接腳的敘述。

 

 

A/D converter   類比數位轉換器

 

  The ATmega controllers used for the Arduino contain an onboard 6 channel (8 channels on the Mini and Nano, 16 on the Mega) analog-to-digital (A/D) converter. The converter has 10 bit resolution, returning integers from 0 to 1023. While the main function of the analog pins for most Arduino users is to read analog sensors, the analog pins also have all the functionality of general purpose input/output (GPIO) pins (the same as digital pins 0 - 13).

 

  Arduino上所使用的ATmega控制器包含板上的6通道類比數位轉換器(Mini跟Nano上是8通道,Mega上是16通道)。

  該轉換器有10位元的解析度,回傳0到1023的整數(10的10次方)。

  對大多數的Arduino使用者,類比接腳的主要功能是用於讀取類比感測器,然而類比接腳也具有通用型輸入輸出接腳(GPIO)的全部功能。(如同接腳0-13)

 

 

  Consequently, if a user needs more general purpose input output pins, and all the analog pins are not in use, the analog pins may be used for GPIO.

  因此,如果使用者需要更多的通用型輸入輸出接腳,並且所有的類比接腳都沒有用到,那類比接腳可以當作GPIO來使用。

 

 

Pin mapping   接腳配置

 

  The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

  類比接腳可以當作數位接腳使用,使用別稱A0(類比輸入腳位0)、A1...等等。

  例如,設定類底接腳0作為輸出的程式碼可能會像下面那樣,並且把它設成HIGH:

 

   pinMode(A0, OUTPUT);
   digitalWrite(A0, HIGH);

 

 

Pull-up resistors   上拉電阻

 

  The analog pins also have pull-up resistors, which work identically to pull-up resistors on the digital pins. They are enabled by issuing a command such as

  類比接腳也有上拉電阻,工作狀況完全跟數位接腳的上拉電阻一樣。  可以藉由像下面的指令被開啟(ENABLE):

 

   pinMode(A0, INPUT_PULLUP);    // set pull-up on analog pin 0 

 

  Be aware however that turning on a pull-up will affect the values reported by analogRead().

  然而,要注意:打開上拉電阻會影響analogRead() 讀取的值。

 

Details and Caveats   細節與警告(附加說明)

 

  The analogRead command will not work correctly if a pin has been previously set to an output, so if this is the case, set it back to an input before using analogRead. Similarly if the pin has been set to HIGH as an output, the pull-up resistor will be set, when switched back to an input.

 

  如果接腳在先前被設定成輸出(OUTPUT), analogRead 指令不會正確工作,所以如果是這種情況,在使用analogRead指令前,記得將接腳設定回輸入(INPUT)。

  同樣地,如果作為輸出的接腳被設定為HIGH,當切換回輸入時,上拉電阻會被設置。

 

 

  The ATmega datasheet also cautions against switching analog pins in close temporal proximity to making A/D readings (analogRead) on other analog pins. This can cause electrical noise and introduce jitter in the analog system. It may be desirable, after manipulating analog pins (in digital mode), to add a short delay before using analogRead() to read other analog pins.

 

  ATmega datasheet 也警告了:不要在太靠近的時間( close temporal proximity)內,切換類比接腳,以在其他類比接腳上進行類比/數位(A/D)讀取(analogRead)。

  這會導致電子雜訊,並在類比系統中引入抖動(jitter)。

  在操作類比接腳(在數位模式)之後,在使用analogRead()讀取其他類比接腳之前,增加一個小時間延遲(delay)應該會比較好。

 

arrow
arrow

    迷途工程師 發表在 痞客邦 留言(0) 人氣()