xiaowu100 发表于 2015-7-21 21:56:19

我的 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
.........

wdjkzym 发表于 2015-7-22 00:12:50

正常                           

Super169 发表于 2015-7-22 00:13:40

沒問題, 官網也清楚說明了:

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]
查看完整版本: 我的 Arduino 信号好乱的样子,这个怎么破?