long debouncing_time = 200; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
volatile bool state = true;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), debounceInterrupt, RISING);
Serial.begin(9600);
}
void loop() {
digitalWrite(13,state);
}
void debounceInterrupt() {
if((long)(micros() - last_micros) >= debouncing_time * 1000) {
blink();
last_micros = micros();
}
}
void blink() {
state = !state;
Serial.print(state);
}
// volatile bool state = true;
// void setup() {
// // put your setup code here, to run once:
// pinMode(2, INPUT_PULLUP);
// pinMode(13, OUTPUT);
// Serial.begin(9600);
// attachInterrupt(digitalPinToInterrupt(2), blink, RISING);
// }
// void loop() {
// // put your main code here, to run repeatedly:
// digitalWrite(13,state);
// }
// void blink(){
// state = !state;
// Serial.println(state);
// }
// bool state = true;
// void setup() {
// // put your setup code here, to run once:
// pinMode(2, INPUT_PULLUP);
// pinMode(13, OUTPUT);
// Serial.begin(9600);
// }
// void loop() {
// // put your main code here, to run repeatedly:
// if (digitalRead(2) == LOW){
// delay(500);
// state = !state;
// Serial.println(state);
// }
// digitalWrite(13,state);
// }
// void setup() {
// // put your setup code here, to run once:
// pinMode(2, INPUT_PULLUP);
// pinMode(13, OUTPUT);
// }
// void loop() {
// // put your main code here, to run repeatedly:
// if (digitalRead(2) == LOW){
// digitalWrite(13, HIGH);
// } else{
// digitalWrite(13, LOW);
// }
// }