Last active
August 29, 2015 14:11
-
-
Save extrasleepy/72aee868899c6ae3493d to your computer and use it in GitHub Desktop.
DetectResets
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
#include <EEPROM.h> | |
byte led = 12; | |
int timesReset = 1; //data stored in EEPROM | |
byte address1 = 0; //location in EEPROM | |
byte address2 = 1; | |
byte retrieved; | |
void setup() { | |
Serial.begin(9600); // sets up serial communication at 9600 bitss per second | |
pinMode(led, OUTPUT); | |
retrieved = readStored(); | |
timesReset+=retrieved; | |
store(); | |
Serial.println(timesReset); | |
} | |
void loop() { | |
digitalWrite(led, !digitalRead(led)); | |
delay(timesReset); | |
} | |
int readStored(){ | |
byte high = EEPROM.read(address1); | |
byte low = EEPROM.read(address2); | |
return (high << 8) + low; | |
} | |
void store(){ | |
//EEPROM.write(address1, highByte(0)); | |
//EEPROM.write(address2, lowByte(0)); | |
EEPROM.write(address1, highByte(timesReset)); | |
EEPROM.write(address2, lowByte(timesReset)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment