#include <EEPROM.h>
// counter rainfall and debounce correction
#define interruptPin 4
#define LED_pin 22
// debounce correction time
unsigned long button_time = 0;
unsigned long last_button_time = 0;
int count = 0;
void IRAM_ATTR handleInterrupt() {
digitalWrite(LED_pin, !digitalRead(LED_pin));
button_time = millis();
if (button_time - last_button_time > 350) {
count++;
last_button_time = button_time;
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_pin, OUTPUT);
pinMode(interruptPin, INPUT);
attachInterrupt(interruptPin, handleInterrupt, FALLING);
}
void loop() {
Serial.println(count);
delay(1000);
}
void EEPROMWritelong(int address, long count) {
byte two = (count & 0xFF);
byte one = ((count>>8) & 0xFF);
EEPROM.write(address, two);
EEPROM.write(address+1, one);
}
long EEPROMReadlong(long address) {
long two = EEPROM.read(address);
long one = EEPROM.read(address+1);
return((two<<0)&0xFF)+((one<<8)&0xFFFF);
}