pinMode()
描述
指定一個 pin 腳做為輸入或者輸出,請見 數位 pin 腳 中的描述,其中有 pin 腳功能的詳細說明。
可以輸入 INPUT_PULLUP
參數來啟用輸入 pin 腳內部的 pull-up 電阻,或是輸入 INPUT
來關閉輸入 pin 腳內部的 pull-up 電阻。
語法
pinMode(pin, mode)
參數
pin
: 你想設定的 pin 腳編號
mode
: INPUT、OUTPUT 或 INPUT_PULLUP。(詳細功能與說明請看 數位 pin 腳)
回傳
無回傳值
範例
int ledPin = 13; // LED 與 pin13 是相連的 void setup() { pinMode(ledPin, OUTPUT); // 設定數位 pin 腳為輸出 } void loop() { digitalWrite(ledPin, HIGH); // 點亮 LED 燈 delay(1000); // 等待一秒 digitalWrite(ledPin, LOW); // 熄滅 LED 燈 delay(1000); // 等待一秒 }
注意
跟 Arduino 不一樣,86Duino 的類比輸入 pin 腳 (像是A0、A1 等) 不能被當作數位 pin 腳。
See also
- constants
- digitalWrite()
- digitalRead()
本頁由熱血青年 LBU 譯自英文版。
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.