极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9300|回复: 1

小弟刚学arduino,不懂为什么会错,求大神指教

[复制链接]
发表于 2013-8-10 17:18:36 | 显示全部楼层 |阅读模式
//This is a simulation code
int led=7;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
int password=Serial.read();
if(Serial.available())
{
if(password>5)
{
for(int i=1;i<10;i++)
{
digitalWrite(led,HIGH);
delay(5000);
digitalWrite(led,LOW);
delay(5000);
}
}
else
{
for(int i=1;i<10;i++)
  {
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(100);
  }
}
}
}


led灯总是不能正常亮,求指教
回复

使用道具 举报

发表于 2013-8-10 17:30:59 | 显示全部楼层
先Serial.available(),確定有資料
再Serial.read(),讀取資料
然後讀進來的估計是char不是int,數字0~9在char要抓48~57
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-10 00:58 , Processed in 0.041262 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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