|
我想要做到按一下就會亮起來,再按就會關掉LED,如些類推,,可是這方法太暴力了,所以想問問有更好的方法嗎
c++沒學好後悔死了......
int PIRSensor = 7;
int ledPin = 13;
int sensorValue = 0;
int ledState = 0;
void setup(){
Serial.begin(9600);
pinMode(PIRSensor, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop(){
sensorValue= digitalRead(PIRSensor);
Serial.println(sensorValue);
if(sensorValue == 1 && count%4==0){
digitalWrite(ledPin, HIGH);
count+=;
}
if(sensorValue == 0 && count%4==1){
digitalWrite(ledPin, HIGH);
count++;
}
if(sensorValue == 1 && count%4==2){
digitalWrite(ledPin, LOW);
count++;
}
if(sensorValue == 0 && count%4==3){
digitalWrite(ledPin, LOW);
count++;
}
}
}
|
|