2222 * and also the correct partition scheme must be selected in Tools->Partition Scheme.
2323 *
2424 * Please check the README.md for instructions and more detailed description.
25- *
25+ *
2626 * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
2727 */
2828
3333#include " ZigbeeCore.h"
3434#include " ep/ZigbeeLight.h"
3535
36- #define LED_PIN RGB_BUILTIN
37- #define BUTTON_PIN 9 // C6/H2 Boot button
38- #define ZIGBEE_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */
39-
40- class MyZigbeeLight : public ZigbeeLight {
41- public:
42- // Constructor that passes parameters to the base class constructor
43- MyZigbeeLight (uint8_t endpoint) : ZigbeeLight(endpoint) {}
36+ #define LED_PIN RGB_BUILTIN
37+ #define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
38+ #define ZIGBEE_LIGHT_ENDPOINT 10
4439
45- // Override the set_on_off function
46- void setOnOff (bool value) override {
47- rgbLedWrite (LED_PIN, 255 * value, 255 * value, 255 * value); // Toggle light
48- }
49- };
40+ ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
5041
51- MyZigbeeLight zbLight = MyZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
42+ /* ******************** RGB LED functions **************************/
43+ void setLED (bool value) {
44+ digitalWrite (LED_PIN, value);
45+ }
5246
5347/* ******************** Arduino functions **************************/
5448void setup () {
55- // Init RMT and leave light OFF
56- rgbLedWrite (LED_PIN, 0 , 0 , 0 );
49+ // Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
50+ pinMode (LED_PIN, OUTPUT);
51+ digitalWrite (LED_PIN, LOW);
5752
5853 // Init button for factory reset
5954 pinMode (BUTTON_PIN, INPUT);
6055
6156 // Optional: set Zigbee device name and model
6257 zbLight.setManufacturerAndModel (" Espressif" , " ZBLightBulb" );
6358
59+ // Set callback function for light change
60+ zbLight.onLightChange (setLED);
61+
6462 // Add endpoint to Zigbee Core
6563 log_d (" Adding ZigbeeLight endpoint to Zigbee Core" );
6664 Zigbee.addEndpoint (&zbLight);
67-
65+
6866 // When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
6967 log_d (" Calling Zigbee.begin()" );
7068 Zigbee.begin ();
7169}
7270
7371void loop () {
74- // Cheking button for factory reset
72+ // Checking button for factory reset
7573 if (digitalRead (BUTTON_PIN) == LOW) { // Push button pressed
7674 // Key debounce handling
7775 delay (100 );
7876 int startTime = millis ();
7977 while (digitalRead (BUTTON_PIN) == LOW) {
8078 delay (50 );
81- if ((millis () - startTime) > 3000 ) {
79+ if ((millis () - startTime) > 3000 ) {
8280 // If key pressed for more than 3secs, factory reset Zigbee and reboot
83- Serial.printf (" Reseting Zigbee to factory settings, reboot.\n " );
81+ Serial.printf (" Resetting Zigbee to factory settings, reboot.\n " );
8482 Zigbee.factoryReset ();
8583 }
8684 }
8785 }
8886 delay (100 );
89- }
87+ }
0 commit comments