#include "Arduino.h"
#include "LowPower.h"
#define SNOOZE_SECS 8
#define START_AT_SECS (8 * 60)
#define RUN_SECS (2 * 60)
#define TOTAL_SECS ( START_AT_SECS + RUN_SECS )
#define BOOST_PIN PIN_PB1 // low to disable
#define BOOST_ENABLE HIGH
#define BOOST_DISABLE LOW
void snooze()
{
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
void app_run()
{
//digitalWrite(BOOST_PIN, BOOST_ENABLE);
pinMode(BOOST_PIN, INPUT); // boost module has pullup
digitalWrite(LED_BUILTIN, HIGH);
}
void app_stop()
{
pinMode(BOOST_PIN, OUTPUT);
digitalWrite(BOOST_PIN, BOOST_DISABLE);
digitalWrite(LED_BUILTIN, LOW);
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(BOOST_PIN, OUTPUT);
digitalWrite(BOOST_PIN, BOOST_DISABLE);
}
void loop()
{
static int running = 0;
static long ticker = START_AT_SECS - 8; // 0;
//static int led_val = LOW;
snooze();
ticker += SNOOZE_SECS;
if (ticker >= START_AT_SECS) {
if (!running) {
app_run();
running = 1;
}
}
if (ticker >= TOTAL_SECS) {
app_stop();
running = 0;
ticker = 0;
}
//digitalWrite(LED_BUILTIN, led_val);
//led_val ^= 1;
}