volatile boolean b1;
volatile boolean b2;
volatile int click;
volatile boolean state;
volatile boolean toggle;
void setup(){
pinMode(6, OUTPUT);
digitalWrite(6,LOW);
pinMode(A2, INPUT_PULLUP);
state = digitalRead(A2);
toggle = 1;
state = 1;
click = 0;
b1 = 0;
b2 = 0;
}
void loop(){
b1 = digitalRead(A2);
if (b1 != state) {
delay(20);
b2 = digitalRead(A2);
if (b2 == b1) {
state = b1;
click = click + 1;
}
}
if (click == 2) {
click = 0;
toggle = !toggle;
digitalWrite(6,toggle);
}
}