求解两个按键控制两盏灯的问题
我想用两个按键控制两盏灯 能够实现任意的点亮熄灭灯 现在的情况是只能按照顺序点亮和熄灭灯 跪求
int redPin=11;
int yellowPin=10;
int redbuttonPin=7;
int yellowbuttonPin=6;
boolean redState=false;
boolean yellowState=false;
void setup()
{
pinMode(redPin,OUTPUT);
pinMode(yellowPin,OUTPUT);
pinMode(redbuttonPin,INPUT_PULLUP);
pinMode(yellowbuttonPin,INPUT_PULLUP);
}
void loop()
{
while(digitalRead(redbuttonPin)==LOW){}
if(redState==true)
{digitalWrite(redPin,LOW);
redState=!redState;
}
else
{
digitalWrite(redPin,HIGH);
redState=!redState;
}
delay(500);
while(digitalRead(yellowbuttonPin)==LOW){}
if(yellowState==true)
{digitalWrite(yellowPin,LOW);
yellowState=!yellowState;
}
else
{
digitalWrite(yellowPin,HIGH);
yellowState=!yellowState;
}
delay(500);
} while(digitalRead(redbuttonPin)==LOW){} 意思是如果不是 Low 那么死循环 zoologist 发表于 2015-4-26 09:44 static/image/common/back.gif
while(digitalRead(redbuttonPin)==LOW){} 意思是如果不是 Low 那么死循环
谢谢大神的指点啊 蓝色骨骨头 发表于 2015-4-26 10:06 static/image/common/back.gif
谢谢大神的指点啊
奇怪 ..
你怎一个问题重复贴文来问 ?
还有, 因为你用 PULLUP 内部上拉电阻:
pinMode(redbuttonPin,INPUT_PULLUP);
所以没有按是 HIGH
按钮按下会变 LOW
tsaiwn 发表于 2015-4-26 19:16 static/image/common/back.gif
奇怪 ..
你怎一个问题重复贴文来问 ?
还有, 因为你用 PULLUP 内部上拉电阻:
谢谢指点哈
页:
[1]