Advertisement
jp112

Interruptcounter

Aug 12th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #define interruptPin D5
  2. volatile bool interruptDetected = false;
  3. int interruptCount = 0;
  4. long oldMillis = 0;
  5.  
  6. void setup() {
  7.   Serial.begin(115200);
  8.   Serial.println("\nStart");
  9.   pinMode(interruptPin, INPUT_PULLUP);
  10.   attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, RISING);
  11. }
  12.  
  13. void handleInterrupt() {
  14.   interruptDetected = true;
  15. }
  16.  
  17. void loop() {
  18.   /*if (oldMillis == 0 || (millis() - oldMillis > 1000)) {          //sekündliche Ausgabe des Pin-Levels
  19.     oldMillis = millis();
  20.     Serial.println("state = "+digitalRead(interruptPin) ? "H":"L");
  21.   }*/
  22.   if (interruptDetected) {
  23.     interruptDetected = false;
  24.     interruptCount++;
  25.     Serial.print("Interrupt erkannt! Gesamt: ");
  26.     Serial.println(interruptCount);
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement