volatile uint32_t count = 0; // Holds the count of interrupts
void incrementCount() {
count++;
}
void setup() {
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), incrementCount, RISING);
}
void loop() {
noInterrupts(); // Disable interrupts to safely read count
uint32_t currentCount = count;
interrupts(); // Re-enable interrupts
if (currentCount % 10 == 0) {
Serial.print("Interrupt count: ");
Serial.println(currentCount);
}
delay(100);
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6