我的 Arduino 信号好乱的样子,这个怎么破?
本帖最后由 xiaowu100 于 2015-7-21 21:58 编辑直接上代码,拔掉所以外围电路,只通过USB连电脑供电。
void setup() {
// put your setup code here, to run once:
int i=2;
for(i=2;i<=12;i++)
{
pinMode(i, INPUT);//将端口设置成输入状态
}
Serial.begin(9600);// 打开串口,设置波特率为9600 bps
}
void loop() {
// put your main code here, to run repeatedly:
int i=2;
for(i=2;i<=12;i++)
{
int in=0;
in = digitalRead(i);//输出每个端口的值
Serial.print(in); //串口输出每个端口的值
}
Serial.println("\t");//换行
delay(500);
}
串口数据是这样的:
00000000000
00000000000
......
00010011111
11111111111
11111111111
.......
11111111111
11111111110
00000000000
00000000000
.........
正常 沒問題, 官網也清楚說明了:
If you have your pin configured as an INPUT, and are reading a switch, when the switch is in the open state the input pin will be "floating", resulting in unpredictable results.
页:
[1]