Skip to content

Instantly share code, notes, and snippets.

@jimthree
Created March 18, 2016 17:09
Show Gist options
  • Save jimthree/17177b042b8c8cb6f1f7 to your computer and use it in GitHub Desktop.
Save jimthree/17177b042b8c8cb6f1f7 to your computer and use it in GitHub Desktop.
#include <EEPROM.h>
// Time to sleep (in seconds):
const int sleepTimeS = 5;
byte sleepCount = 0;
bool debug = true;
void setup()
{
if (debug) Serial.begin(115200);
if (debug) Serial.println("DeeplSleep test\n");
if (debug) Serial.println("---------------\n");
EEPROM.begin(1); // initialise EEPROM to store only one byte
if (debug) Serial.println("- EEPROM inislised with 1 byte\n");
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
if (debug) Serial.println("- Reading EEPROM at address 0\n");
sleepCount = EEPROM.read(0); // Read whatever value is in the EEPROM 0 byte
if (debug) Serial.println("- EEPROM read, value is: " + String(sleepCount) + "\n");
if (debug) Serial.println("- Gonna flash some LEDs now\n");
for (int i = 0; i < sleepCount; i++)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
}
if (debug) Serial.println("- Finished flashing Leds, now going to write " + String(sleepCount+1) + " to the EEPROM\n");
// EEPROM.write(addr, val);
EEPROM.write(0, sleepCount+1);
if (debug) Serial.println("- Finished writeing " + String(sleepCount+1) + " to the EEPROM\n");
if (debug) Serial.println("- Pause for a second and take a deep breath\n");
delay(1000);
if (debug) Serial.println("- Gonna go to sleep for "+ String(sleepTimeS) +" Seconds\n");
ESP.deepSleep(sleepTimeS * 1000000);
if (debug) Serial.println("- ZZZZZZZZZzzzzzzzzzzz z z z z z\n");
delay(1000);
}
// the loop function runs over and over again forever
void loop()
{
//you aint seen me right?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment