-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapp.cpp
47 lines (38 loc) · 1.03 KB
/
app.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright (c) 2025 Purva Yeshi <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <Arduino.h>
#include "EEPROM.h"
void setup() {
/* Initialize serial communication */
Serial.begin(115200);
while (!Serial) {
; /* Wait for serial port to connect (needed for boards with native USB) */
}
Serial.println("Serial communication initialized");
/* Initialize EEPROM/NVS */
if (EEPROM.nvs_init() < 0) {
Serial.println("NVS initialization failed");
return;
}
Serial.println("NVS initialized");
/* Write data to EEPROM */
int data = 1234; // Example data to store
if (EEPROM.write_data(1, &data, sizeof(data)) < 0) {
Serial.println("Failed to write data");
} else {
Serial.println("Data written successfully");
}
/* Read data from EEPROM */
int read_data = 0;
if (EEPROM.read_data(1, &read_data, sizeof(read_data)) > 0) {
Serial.print("Data read: ");
Serial.println(read_data);
} else {
Serial.println("Failed to read data");
}
}
void loop() {
}