验证中...
gistfile1.txt
Raw Copy
volatile int b1;
volatile int b2;
volatile int click;
volatile int laststate;
volatile int toggle;
void setup(){
click = 0;
laststate = digitalRead(13);
toggle = 0;
b1 = 0;
b2 = 0;
pinMode(13, INPUT_PULLUP);
pinMode(8, OUTPUT);
}
void loop(){
if (digitalRead(13) == 0) {
b1 = !digitalRead(13);
if (b1 != laststate) {
delay(20);
b2 = digitalRead(13);
if (b1 == b2) {
laststate = b1;
click = click + 1;
}
}
if (click == 1) {
toggle = 1 - toggle;
digitalWrite(8,toggle);
}
if (click == 2) {
click = 0;
toggle = 1 - toggle;
digitalWrite(8,toggle);
}
delay(1000);
}
}
按钮继电器.jpg

Comment list( 0 )

Sign in for post a comment

Help Search