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.