Sometimes it works for several "completions" - other times it craches when the counter is e.g. 600 or 900.
I have tried with two different ESP modules and its running stable if I disable the "attachInterrupt" code.
Any input is appreciated.
const int pinFlowmeter = 13;
volatile unsigned int intCounter=0;
void setup() {
}
void loop() {
if (intCounter >= 1000) {
detachInterrupt(digitalPinToInterrupt(pinFlowmeter));
Serial.println("Complete");
intCounter = 0;
buttonPressed = false;
}
// ... other stuff
}
void pressButton() {
if (!buttonPressed) { // prevent calling this several times
attachInterrupt(digitalPinToInterrupt(pinFlowmeter), getcount, CHANGE);
buttonPressed = true;
}
}
void getcount() {
intCounter++;
}
Lars Bo Wassini