38 lines
720 B
C++
38 lines
720 B
C++
#include <Arduino.h>
|
|
#include <TinyPower.h>
|
|
#include "ContactSensor.h"
|
|
|
|
#define MINUTES(value) (uint16_t)(value*60/8) // minutes*60(seconds)/8s(WDT)
|
|
#define HOURS(value) MINUTES(value)*60
|
|
|
|
#define SEND_INTERVAL MINUTES(2)
|
|
#define SEND_VCC_INTERVAL HOURS(6)
|
|
|
|
// Pins
|
|
#define SENDER_PIN PIN_B2
|
|
|
|
volatile uint16_t counter = 0;
|
|
ContactSensor sensor(PRESENCE_SENSOR);
|
|
|
|
void setup() {
|
|
|
|
TinySwitch::setup(SENDER_PIN);
|
|
TinyPower::setup();
|
|
TinyPower::enableWdt(WDTO_8S);
|
|
}
|
|
|
|
void loop() {
|
|
if (counter == 0) {
|
|
sensor.sendStateAndVoltage(false);
|
|
} else if (counter % SEND_INTERVAL == 0) {
|
|
sensor.sendState(false);
|
|
}
|
|
TinyPower::sleep();
|
|
}
|
|
|
|
ISR(WDT_vect) {
|
|
if (++counter % SEND_VCC_INTERVAL == 0) {
|
|
counter = 0;
|
|
}
|
|
}
|