33
33
34
34
#include " Zigbee.h"
35
35
36
- #define LED_PIN RGB_BUILTIN
37
- #define BUTTON_PIN 9 // C6/H2 Boot button
38
- #define ZIGBEE_LIGHT_ENDPOINT 10
36
+ /* Zigbee color dimmable light configuration */
37
+ #define ZIGBEE_RGB_LIGHT_ENDPOINT 10
38
+ uint8_t led = RGB_BUILTIN;
39
+ uint8_t button = BOOT_PIN;
39
40
40
- ZigbeeColorDimmableLight zbColorLight = ZigbeeColorDimmableLight(ZIGBEE_LIGHT_ENDPOINT );
41
+ ZigbeeColorDimmableLight zbColorLight = ZigbeeColorDimmableLight(ZIGBEE_RGB_LIGHT_ENDPOINT );
41
42
42
43
/* ******************** RGB LED functions **************************/
43
44
void setRGBLight (bool state, uint8_t red, uint8_t green, uint8_t blue, uint8_t level) {
44
45
if (!state) {
45
- rgbLedWrite (LED_PIN , 0 , 0 , 0 );
46
+ rgbLedWrite (led , 0 , 0 , 0 );
46
47
return ;
47
48
}
48
49
float brightness = (float )level / 255 ;
49
- rgbLedWrite (LED_PIN , red * brightness, green * brightness, blue * brightness);
50
+ rgbLedWrite (led , red * brightness, green * brightness, blue * brightness);
50
51
}
51
52
52
53
// Create a task on identify call to handle the identify function
@@ -58,7 +59,7 @@ void identify(uint16_t time) {
58
59
zbColorLight.restoreLight ();
59
60
return ;
60
61
}
61
- rgbLedWrite (LED_PIN , 255 * blink, 255 * blink, 255 * blink);
62
+ rgbLedWrite (led , 255 * blink, 255 * blink, 255 * blink);
62
63
blink = !blink;
63
64
}
64
65
@@ -70,10 +71,10 @@ void setup() {
70
71
}
71
72
72
73
// Init RMT and leave light OFF
73
- rgbLedWrite (LED_PIN , 0 , 0 , 0 );
74
+ rgbLedWrite (led , 0 , 0 , 0 );
74
75
75
76
// Init button for factory reset
76
- pinMode (BUTTON_PIN , INPUT_PULLUP);
77
+ pinMode (button , INPUT_PULLUP);
77
78
78
79
// Set callback function for light change
79
80
zbColorLight.onLightChange (setRGBLight);
@@ -104,11 +105,11 @@ void setup() {
104
105
105
106
void loop () {
106
107
// Checking button for factory reset
107
- if (digitalRead (BUTTON_PIN ) == LOW) { // Push button pressed
108
+ if (digitalRead (button ) == LOW) { // Push button pressed
108
109
// Key debounce handling
109
110
delay (100 );
110
111
int startTime = millis ();
111
- while (digitalRead (BUTTON_PIN ) == LOW) {
112
+ while (digitalRead (button ) == LOW) {
112
113
delay (50 );
113
114
if ((millis () - startTime) > 3000 ) {
114
115
// If key pressed for more than 3secs, factory reset Zigbee and reboot
0 commit comments