Created
August 12, 2020 04:36
-
-
Save sivar2311/4627e83eeb63602e4602def958b4fac7 to your computer and use it in GitHub Desktop.
EEPROM_Check
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 <Arduino.h> | |
#include <EEPROM.h> | |
#define MAGIC_BYTE 0xDD | |
bool checkInit() { | |
return (EEPROM.read(0) == MAGIC_BYTE); | |
} | |
void initializeEEPROM() { | |
Serial.printf("Initializing EEPROM\r\n"); | |
EEPROM.write(0, MAGIC_BYTE); | |
for (int i=1; i<5; i++) { | |
EEPROM.write(i, i); | |
} | |
EEPROM.commit(); | |
} | |
void setup() { | |
Serial.begin(115200); Serial.printf("\r\n\r\n"); | |
EEPROM.begin(5); | |
if (!checkInit()) initializeEEPROM(); | |
for (int i=1; i<5; i++) { | |
unsigned char x = EEPROM.read(i); | |
Serial.printf("EEPROM.read(%d): %d\t", i, x); | |
x++; | |
Serial.printf("EEPROM.write(%d, %d)\r\n", i, x); | |
EEPROM.write(i, x); | |
} | |
EEPROM.end(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment