极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11851|回复: 2

我的 Arduino 信号好乱的样子,这个怎么破?

[复制链接]
发表于 2015-7-21 21:56:19 | 显示全部楼层 |阅读模式
本帖最后由 xiaowu100 于 2015-7-21 21:58 编辑

直接上代码,拔掉所以外围电路,只通过USB连电脑供电。[code]

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
.........
回复

使用道具 举报

发表于 2015-7-22 00:12:50 | 显示全部楼层
正常                           
回复 支持 反对

使用道具 举报

发表于 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.

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-16 18:55 , Processed in 0.037215 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表