22
22
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23
23
*
24
24
* Please check the README.md for instructions and more detailed description.
25
- *
25
+ *
26
26
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27
27
*/
28
28
33
33
#include " ZigbeeCore.h"
34
34
#include " ep/ZigbeeLight.h"
35
35
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
44
39
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);
50
41
51
- MyZigbeeLight zbLight = MyZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
42
+ /* ******************** RGB LED functions **************************/
43
+ void setLED (bool value) {
44
+ digitalWrite (LED_PIN, value);
45
+ }
52
46
53
47
/* ******************** Arduino functions **************************/
54
48
void 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);
57
52
58
53
// Init button for factory reset
59
54
pinMode (BUTTON_PIN, INPUT);
60
55
61
56
// Optional: set Zigbee device name and model
62
57
zbLight.setManufacturerAndModel (" Espressif" , " ZBLightBulb" );
63
58
59
+ // Set callback function for light change
60
+ zbLight.onLightChange (setLED);
61
+
64
62
// Add endpoint to Zigbee Core
65
63
log_d (" Adding ZigbeeLight endpoint to Zigbee Core" );
66
64
Zigbee.addEndpoint (&zbLight);
67
-
65
+
68
66
// When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
69
67
log_d (" Calling Zigbee.begin()" );
70
68
Zigbee.begin ();
71
69
}
72
70
73
71
void loop () {
74
- // Cheking button for factory reset
72
+ // Checking button for factory reset
75
73
if (digitalRead (BUTTON_PIN) == LOW) { // Push button pressed
76
74
// Key debounce handling
77
75
delay (100 );
78
76
int startTime = millis ();
79
77
while (digitalRead (BUTTON_PIN) == LOW) {
80
78
delay (50 );
81
- if ((millis () - startTime) > 3000 ) {
79
+ if ((millis () - startTime) > 3000 ) {
82
80
// 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 " );
84
82
Zigbee.factoryReset ();
85
83
}
86
84
}
87
85
}
88
86
delay (100 );
89
- }
87
+ }
0 commit comments