Skip to content

Commit 4eece9b

Browse files
authored
feat(matter): add minimum matter ednpoint action to example
1 parent b0bbf2a commit 4eece9b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

libraries/Matter/examples/MatterMinimum/MatterMinimum.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@
2727
// Single On/Off Light Endpoint - at least one per node
2828
MatterOnOffLight OnOffLight;
2929

30+
// Light GPIO that can be controlled by Matter APP
31+
#ifdef LED_BUILTIN
32+
const uint8_t ledPin = LED_BUILTIN;
33+
#else
34+
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
35+
#endif
36+
37+
// Matter Protocol Endpoint (On/OFF Light) Callback
38+
bool matterCB(bool state) {
39+
digitalWrite(ledPin, state ? HIGH : LOW);
40+
// This callback must return the success state to Matter core
41+
return true;
42+
}
43+
3044
// WiFi is manually set and started
3145
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
3246
const char *password = "your-password"; // Change this to your WiFi password
3347

3448
void setup() {
49+
// Initialise the LED GPIO
50+
pinMode(ledPin, OUTPUT);
51+
3552
WiFi.enableIPv6(true);
3653
// Manually connect to WiFi
3754
WiFi.begin(ssid, password);
@@ -43,6 +60,9 @@ void setup() {
4360
// Initialize at least one Matter EndPoint
4461
OnOffLight.begin();
4562

63+
// Associate a callback to the Matter Controller
64+
OnOffLight.onChange(matterCB);
65+
4666
// Matter beginning - Last step, after all EndPoints are initialized
4767
Matter.begin();
4868

0 commit comments

Comments
 (0)