1
1
/*
2
- ESP32 start counter example with Preferences library
2
+ ESP32 startup counter example with Preferences library.
3
3
4
- This simple example demonstrate using Preferences library to store how many times
5
- was ESP32 module started. Preferences library is wrapper around Non-volatile
4
+ This simple example demonstrates using the Preferences library to store how many times
5
+ the ESP32 module has booted. The Preferences library is a wrapper around the Non-volatile
6
6
storage on ESP32 processor.
7
7
8
8
created for arduino-esp32 09 Feb 2017
@@ -17,29 +17,29 @@ void setup() {
17
17
Serial.begin (115200 );
18
18
Serial.println ();
19
19
20
- // Open Preferences with my-app namespace. Each application module, library, etc.
21
- // has to use namespace name to prevent key name collisions. We will open storage in
20
+ // Open Preferences with my-app namespace. Each application module, library, etc
21
+ // has to use a namespace name to prevent key name collisions. We will open storage in
22
22
// RW-mode (second parameter has to be false).
23
- // Note: Namespace name is limited to 15 chars
23
+ // Note: Namespace name is limited to 15 chars.
24
24
preferences.begin (" my-app" , false );
25
25
26
- // Remove all preferences under opened namespace
26
+ // Remove all preferences under the opened namespace
27
27
// preferences.clear();
28
28
29
29
// Or remove the counter key only
30
30
// preferences.remove("counter");
31
31
32
- // Get a counter value, if key is not exist return default value 0
33
- // Note: Key name is limited to 15 chars too
32
+ // Get the counter value, if the key does not exist, return a default value of 0
33
+ // Note: Key name is limited to 15 chars.
34
34
unsigned int counter = preferences.getUInt (" counter" , 0 );
35
35
36
- // Increase counter
36
+ // Increase counter by 1
37
37
counter++;
38
38
39
- // Print counter to a Serial
39
+ // Print the counter to Serial Monitor
40
40
Serial.printf (" Current counter value: %u\n " , counter);
41
41
42
- // Store counter to the Preferences
42
+ // Store the counter to the Preferences
43
43
preferences.putUInt (" counter" , counter);
44
44
45
45
// Close the Preferences
@@ -53,4 +53,4 @@ void setup() {
53
53
ESP.restart ();
54
54
}
55
55
56
- void loop () {}
56
+ void loop () {}
0 commit comments