2018-03-04 20:22:48 +01:00
|
|
|
/*
|
|
|
|
ESP32 eeprom_class example with EEPROM library
|
|
|
|
This simple example demonstrates using EEPROM library to store different data in
|
2019-07-09 18:34:04 +02:00
|
|
|
ESP32 Flash memory in a multiple user-defined EEPROM class objects.
|
2018-03-04 20:22:48 +01:00
|
|
|
|
|
|
|
Created for arduino-esp32 on 25 Dec, 2017
|
|
|
|
by Elochukwu Ifediora (fedy0)
|
2019-07-09 18:34:04 +02:00
|
|
|
converted to nvs by lbernstone - 06/22/2019
|
2018-03-04 20:22:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "EEPROM.h"
|
|
|
|
|
2019-07-09 18:34:04 +02:00
|
|
|
// Instantiate eeprom objects with parameter/argument names and sizes
|
2019-04-23 22:55:12 +02:00
|
|
|
EEPROMClass NAMES("eeprom0", 0x500);
|
|
|
|
EEPROMClass HEIGHT("eeprom1", 0x200);
|
2018-03-04 20:22:48 +01:00
|
|
|
EEPROMClass AGE("eeprom2", 0x100);
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Testing EEPROMClass\n");
|
|
|
|
if (!NAMES.begin(NAMES.length())) {
|
|
|
|
Serial.println("Failed to initialise NAMES");
|
|
|
|
Serial.println("Restarting...");
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
if (!HEIGHT.begin(HEIGHT.length())) {
|
|
|
|
Serial.println("Failed to initialise HEIGHT");
|
|
|
|
Serial.println("Restarting...");
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
if (!AGE.begin(AGE.length())) {
|
|
|
|
Serial.println("Failed to initialise AGE");
|
|
|
|
Serial.println("Restarting...");
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
|
|
|
|
char* name = "Teo Swee Ann";
|
|
|
|
double height = 5.8;
|
|
|
|
uint32_t age = 47;
|
|
|
|
|
2019-07-09 18:34:04 +02:00
|
|
|
// Write: Variables ---> EEPROM stores
|
2018-03-04 20:22:48 +01:00
|
|
|
NAMES.put(0, name);
|
|
|
|
HEIGHT.put(0, height);
|
|
|
|
AGE.put(0, age);
|
|
|
|
Serial.print("name: "); Serial.println(name);
|
|
|
|
Serial.print("height: "); Serial.println(height);
|
|
|
|
Serial.print("age: "); Serial.println(age);
|
|
|
|
Serial.println("------------------------------------\n");
|
|
|
|
|
|
|
|
// Clear variables
|
|
|
|
name = '\0';
|
|
|
|
height = 0;
|
|
|
|
age = 0;
|
|
|
|
Serial.print("name: "); Serial.println(name);
|
|
|
|
Serial.print("height: "); Serial.println(height);
|
|
|
|
Serial.print("age: "); Serial.println(age);
|
|
|
|
Serial.println("------------------------------------\n");
|
|
|
|
|
2019-07-09 18:34:04 +02:00
|
|
|
// Read: Variables <--- EEPROM stores
|
2018-03-04 20:22:48 +01:00
|
|
|
NAMES.get(0, name);
|
|
|
|
HEIGHT.get(0, height);
|
|
|
|
AGE.get(0, age);
|
|
|
|
Serial.print("name: "); Serial.println(name);
|
|
|
|
Serial.print("height: "); Serial.println(height);
|
|
|
|
Serial.print("age: "); Serial.println(age);
|
|
|
|
|
|
|
|
Serial.println("Done!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2019-07-09 18:34:04 +02:00
|
|
|
delay(0xFFFFFFFF);
|
2018-03-04 20:22:48 +01:00
|
|
|
}
|