//sekcja ACO
volatile bool gotReset = false;
volatile uint16_t pulseCount = 0;
volatile unsigned long lastEdgeTime = 0;
volatile bool counting = false;
volatile unsigned long lastPulseMillis = 0;
static unsigned long lastActivity = 0;
static bool resetPublished = false;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
unsigned long ringStart = 0;
bool wasRinging = false;
bool printed = false;
int lastState = HIGH;
unsigned long lastStateChange = 0;
//Przerwanie wchodzi tutaj...
void IRAM_ATTR handleInterrupt() {
unsigned long now = micros();
static unsigned long lastEdge = 0;
unsigned long duration = now - lastEdge;
lastEdge = now;
portENTER_CRITICAL_ISR(&mux);
// RESET: 370 ms przerwy (LOW) na linii
if (!gotReset && duration > 300000) {
gotReset = true;
counting = true;
pulseCount = 0;
lastPulseMillis = millis();
}
// Impulsy numeru lokalu (25us + 77us)
if (gotReset && counting && duration > 20 && duration < 40) {
pulseCount++;
lastPulseMillis = millis();
}
portEXIT_CRITICAL_ISR(&mux);
}
///A tak rejestruje przerwanie:
pinMode(IO4, INPUT);
attachInterrupt(digitalPinToInterrupt(IO4), handleInterrupt, FALLING);
Źródło: