Код: Выделить всё
/**
ТЕСТОВЫЙ СКЕТЧ КОНТРОЛЯ ИНТЕРВАЛОВ ВРЕМЕНИ ВО СНЕ С ПРЕРЫВАНИЯМИ
*/
unsigned long oldmillis;
unsigned long newmillis;
unsigned long interrupt_time;
int8_t timer_status = 0;
unsigned long SLEEP_TIME = 20000;
unsigned long SLEEP_TIME_W;
#define MY_DEBUG
#define MY_RADIO_NRF5_ESB /// ONLY NRF52 SERIES !!!
//#define MY_RADIO_RF24 /// NOT WORKING !!!!
#include <MySensors.h>
void setup()
{
pinMode(2, INPUT_PULLUP);
SLEEP_TIME_W = SLEEP_TIME;
Serial.println("#######################################################");
Serial.println("MONITORING AND REASSIGNING SLEEP TIME, .........GO!!!!!");
Serial.println("#######################################################");
}
void presentation()
{
sendSketchInfo("SleepTimeControl nRF5", "1.0");
}
void loop()
{
oldmillis = millis();
timer_status = sleep(digitalPinToInterrupt(2), FALLING, SLEEP_TIME_W);
if (timer_status == 2) {
newmillis = millis();
interrupt_time = newmillis - oldmillis;
SLEEP_TIME_W = SLEEP_TIME_W - interrupt_time;
Serial.println("#######################################################");
Serial.print("WAS IN A SLEEP: ");
Serial.print(newmillis - oldmillis);
Serial.println(" MILLISECONDS");
Serial.println("#######################################################");
Serial.print("GO TO SLEEP FOR: ");
Serial.print(SLEEP_TIME_W);
Serial.println(" MILLISECONDS");
Serial.println("#######################################################");
}
if (timer_status == -1) {
newmillis = millis();
SLEEP_TIME_W = SLEEP_TIME;
Serial.println("#######################################################");
Serial.print("WOKE UP ON SCHEDULE EVERY ");
Serial.print(SLEEP_TIME);
Serial.println(" MILLISECONDS");
Serial.println("#######################################################");
Serial.print("TOTAL TIME SINCE THE START OF THE PROGRAM - ");
Serial.print(millis());
Serial.println(" MILLISECONDS");
Serial.println("#######################################################");
}
}