Dodany przez: klima, 16:08 16-10-2025

Nowy Pobierz
  1.  
  2. //sekcja ACO
  3. volatile bool gotReset = false;
  4. volatile uint16_t pulseCount = 0;
  5. volatile unsigned long lastEdgeTime = 0;
  6. volatile bool counting = false;
  7. volatile unsigned long lastPulseMillis = 0;
  8.  
  9. static unsigned long lastActivity = 0;
  10. static bool resetPublished = false;
  11.  
  12.  
  13. portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
  14.  
  15. unsigned long ringStart = 0;
  16. bool wasRinging = false;
  17. bool printed = false;
  18. int lastState = HIGH;
  19. unsigned long lastStateChange = 0;
  20.  
  21. //Przerwanie wchodzi tutaj...
  22. void IRAM_ATTR handleInterrupt() {
  23.   unsigned long now = micros();
  24.   static unsigned long lastEdge = 0;
  25.   unsigned long duration = now - lastEdge;
  26.   lastEdge = now;
  27.  
  28.   portENTER_CRITICAL_ISR(&mux);
  29.  
  30.   // RESET: 370 ms przerwy (LOW) na linii
  31.   if (!gotReset && duration > 300000) {
  32.     gotReset = true;
  33.     counting = true;
  34.     pulseCount = 0;
  35.     lastPulseMillis = millis();
  36.   }
  37.  
  38.   // Impulsy numeru lokalu (25us + 77us)
  39.   if (gotReset && counting && duration > 20 && duration < 40) {
  40.     pulseCount++;
  41.     lastPulseMillis = millis();
  42.   }
  43.  
  44.   portEXIT_CRITICAL_ISR(&mux);
  45. }
  46.  
  47. ///A tak rejestruje przerwanie:
  48. pinMode(IO4, INPUT);
  49. attachInterrupt(digitalPinToInterrupt(IO4), handleInterrupt, FALLING);
  50.  
  51.  
  52.  

Źródło:

Ostatnie wpisy

Linki

Funkcje