|
22 | 22 | MatterDimmableLight DimmableLight; |
23 | 23 |
|
24 | 24 | // it will keep last OnOff & Brightness state stored, using Preferences |
25 | | -Preferences lastStatePref; |
| 25 | +Preferences matterPref; |
| 26 | +const char *onOffPrefKey = "OnOffState"; |
| 27 | +const char *brightnessPrefKey = "BrightnessState"; |
26 | 28 |
|
27 | 29 | // set your board RGB LED pin here |
28 | 30 | #ifdef RGB_BUILTIN |
@@ -51,8 +53,8 @@ bool setLightState(bool state, uint8_t brightness) { |
51 | 53 | digitalWrite(ledPin, LOW); |
52 | 54 | } |
53 | 55 | // store last Brightness and OnOff state for when the Light is restarted / power goes off |
54 | | - lastStatePref.putUChar("lastBrightness", brightness); |
55 | | - lastStatePref.putBool("lastOnOffState", state); |
| 56 | + matterPref.putUChar(brightnessPrefKey, brightness); |
| 57 | + matterPref.putBool(onOffPrefKey, state); |
56 | 58 | // This callback must return the success state to Matter core |
57 | 59 | return true; |
58 | 60 | } |
@@ -86,11 +88,11 @@ void setup() { |
86 | 88 | delay(500); |
87 | 89 |
|
88 | 90 | // Initialize Matter EndPoint |
89 | | - lastStatePref.begin("matterLight", false); |
| 91 | + matterPref.begin("MatterPrefs", false); |
90 | 92 | // default OnOff state is ON if not stored before |
91 | | - bool lastOnOffState = lastStatePref.getBool("lastOnOffState", true); |
| 93 | + bool lastOnOffState = matterPref.getBool(onOffPrefKey, true); |
92 | 94 | // default brightness ~= 6% (15/255) |
93 | | - uint8_t lastBrightness = lastStatePref.getUChar("lastBrightness", 15); |
| 95 | + uint8_t lastBrightness = matterPref.getUChar(brightnessPrefKey, 15); |
94 | 96 | DimmableLight.begin(lastOnOffState, lastBrightness); |
95 | 97 | // set the callback function to handle the Light state change |
96 | 98 | DimmableLight.onChange(setLightState); |
|
0 commit comments