求解两个按键控制两盏灯的问题
我想用两个按键控制两盏灯 能够实现任意的点亮熄灭灯 现在的情况是只能按照顺序点亮和熄灭灯 跪求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){}
阻碍了后面的判断,这样写就会一直等待button为low,换个写法吧 拉普拉斯妖 发表于 2015-4-26 12:17
while(digitalRead(redbuttonPin)==LOW){}
阻碍了后面的判断,这样写就会一直等待button为low,换个写法吧 ...
谢谢了
页:
[1]