|
我想用两个按键控制两盏灯 能够实现任意的点亮熄灭灯 现在的情况是只能按照顺序点亮和熄灭灯 跪求
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);
}
|
|