1
|
const byte interruptPin = 25;
|
1
|
volatile int interruptCounter = 0;
|
1
|
int numberOfInterrupts = 0;
|
1
|
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
1
2
|
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
|
1
|
pinMode(interruptPin, INPUT_PULLUP);
|
1
|
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
const byte interruptPin = 25;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void setup() {
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
}
|
1
2
3
4
5
6
7
8
|
if(interruptCounter>0){
portENTER_CRITICAL(&mux);
interruptCounter--;
portEXIT_CRITICAL(&mux);
//Handle the interrupt
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void loop() {
if(interruptCounter>0){
portENTER_CRITICAL(&mux);
interruptCounter--;
portEXIT_CRITICAL(&mux);
numberOfInterrupts++;
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
}
}
|
1
2
3
4
5
|
void handleInterrupt() {
portENTER_CRITICAL_ISR(&mux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&mux);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
const byte interruptPin = 25;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void setup() {
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
}
void handleInterrupt() {
portENTER_CRITICAL_ISR(&mux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&mux);
}
void loop() {
if(interruptCounter>0){
portENTER_CRITICAL(&mux);
interruptCounter--;
portEXIT_CRITICAL(&mux);
numberOfInterrupts++;
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
}
}
|