Created
June 29, 2020 05:25
-
-
Save futureshocked/c4bb1b650aa5dc5524973d1be9133fda to your computer and use it in GitHub Desktop.
This sketch will simply blink an LED at a 1Hz frequency and increment the counter in EEPROM address 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written by Peter Dalmaris from Tech Explorations. | |
// Used to find out how long an ESP32 can last on a LiPo battery. | |
// This sketch will simply blink an LED at a 1Hz frequency. | |
// It will increment the counter in EEPROM address 0 every time it blinks. | |
// https://techexplorations.com | |
#include "EEPROM.h" | |
int addr = 0; | |
#define EEPROM_SIZE 32 | |
byte led_pin = 5; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("start..."); | |
if (!EEPROM.begin(EEPROM_SIZE)) | |
{ | |
Serial.println("failed to initialise EEPROM"); delay(1000000); | |
} | |
// initialize digital pin LED_BUILTIN as an output. | |
pinMode(led_pin, OUTPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
long count = EEPROM.readULong(addr); | |
count++; | |
EEPROM.writeULong(addr, count); | |
EEPROM.commit(); | |
Serial.println(count); | |
digitalWrite(led_pin, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(500); // wait for a second | |
digitalWrite(led_pin, LOW); // turn the LED off by making the voltage LOW | |
delay(500); // wait for a second | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment