Closed
Description
Description:
Hey I would like to use interrupts on buttons. However if I put a cap for debouncing the slow rising/falling edge triggers between 15/25 events with 100nF / 10K. Bigger Caps only increase the number of events. No cap results in a bouncy signal.
Also it seems that Falling/Rising edge does not work on slow edges.
If the dectection is depending on the rise/fall time than I don't see a reliable way of implementing anything with interrupts.
Sketch:
#include <Arduino.h>
const byte interruptPin = 27;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR handleInterrupt() {
portENTER_CRITICAL_ISR(&mux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&mux);
}
void setup() {
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
}
void loop() {
if(interruptCounter>0){
portENTER_CRITICAL(&mux);
interruptCounter--;
portEXIT_CRITICAL(&mux);
numberOfInterrupts++;
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
}
delay(50);
}