Skip to content

Instantly share code, notes, and snippets.

@sivar2311
Created August 12, 2020 04:36
Show Gist options
  • Save sivar2311/4627e83eeb63602e4602def958b4fac7 to your computer and use it in GitHub Desktop.
Save sivar2311/4627e83eeb63602e4602def958b4fac7 to your computer and use it in GitHub Desktop.
EEPROM_Check
#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