Template
54 lines
897 B
C++
54 lines
897 B
C++
#include <Arduino.h>
|
|
#include "hot_water.h"
|
|
|
|
|
|
|
|
#define ANALOG_READ_PIN A1
|
|
|
|
void mqtt_setup();
|
|
void mqtt_loop();
|
|
|
|
void hotwater_setup();
|
|
void hotwater_loop();
|
|
|
|
volatile boolean intflag_FLOW = false; // external GPIO interrupt (event)
|
|
volatile unsigned long ticktime = 0;
|
|
volatile unsigned int ticknum = 0;
|
|
volatile unsigned long FLOW_eventtime = 0;
|
|
|
|
unsigned long FLOW_starttime;
|
|
unsigned long FLOW_stoptime;
|
|
|
|
// declare Timer3_ISR functions
|
|
void startTimer(int frequencyHz);
|
|
|
|
// TC3 ISR callback
|
|
void Tick(void) {
|
|
ticknum++;
|
|
ticktime++;
|
|
}
|
|
|
|
// pin interrupt handler CHANGE
|
|
void flowstate(void) {
|
|
intflag_FLOW = true;
|
|
FLOW_eventtime = millis(); // note flow event time
|
|
}
|
|
|
|
|
|
void setup() {
|
|
pinMode(ANALOG_READ_PIN, INPUT);
|
|
|
|
startTimer(RATE);
|
|
|
|
#if (SERIAL_DEBUGGING)
|
|
DBEGIN(115200);
|
|
#endif
|
|
mqtt_setup();
|
|
hotwater_setup();
|
|
}
|
|
|
|
void loop() {
|
|
hotwater_loop();
|
|
mqtt_loop();
|
|
}
|