Skip to content

Commit

Permalink
Add workaround for weird double interrupt trigger bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
BIOS9 committed Sep 15, 2021
1 parent 7d7d997 commit fa5d5fa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions SmartMeterMonitor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
#include "OTA.h"
#include "PrometheusExporter.h"

#define IMPULSE_PIN 34
#define IMPULSE_PIN 27
#define LED_PIN 32

Network network;
OTA ota;
PrometheusExporter exporter;

int impulseCount = 0;
unsigned int impulseCount = 0;
unsigned long led_time = 0;

void IRAM_ATTR impulse() {
++impulseCount;
exporter.setImpulses(impulseCount);
digitalWrite(LED_PIN, HIGH);
led_time = millis();
if(digitalRead(IMPULSE_PIN) == LOW) {
++impulseCount;
exporter.setImpulses(impulseCount);
digitalWrite(LED_PIN, HIGH);
led_time = millis();
}
}

void setup() {
Expand All @@ -25,8 +27,8 @@ void setup() {
ota.init();
exporter.init();
pinMode(LED_PIN, OUTPUT);
pinMode(IMPULSE_PIN, INPUT);
attachInterrupt(IMPULSE_PIN, impulse, CHANGE);
pinMode(IMPULSE_PIN, INPUT_PULLUP);
attachInterrupt(IMPULSE_PIN, impulse, FALLING);
}

void loop() {
Expand Down

0 comments on commit fa5d5fa

Please sign in to comment.