|
32 | 32 |
|
33 | 33 | #include "Zigbee.h"
|
34 | 34 |
|
35 |
| -#define LED_PIN RGB_BUILTIN |
36 |
| -#define BUTTON_PIN 9 // ESP32-C6/H2 Boot button |
| 35 | +/* Zigbee light bulb configuration */ |
37 | 36 | #define ZIGBEE_LIGHT_ENDPOINT 10
|
| 37 | +uint8_t led = RGB_BUILTIN; |
| 38 | +uint8_t button = BOOT_PIN; |
38 | 39 |
|
39 | 40 | ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
|
40 | 41 |
|
41 | 42 | /********************* RGB LED functions **************************/
|
42 | 43 | void setLED(bool value) {
|
43 |
| - digitalWrite(LED_PIN, value); |
| 44 | + digitalWrite(led, value); |
44 | 45 | }
|
45 | 46 |
|
46 | 47 | /********************* Arduino functions **************************/
|
47 | 48 | void setup() {
|
48 | 49 | Serial.begin(115200);
|
49 |
| - while (!Serial) { |
50 |
| - delay(10); |
51 |
| - } |
| 50 | + |
52 | 51 | // Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
|
53 |
| - pinMode(LED_PIN, OUTPUT); |
54 |
| - digitalWrite(LED_PIN, LOW); |
| 52 | + pinMode(led, OUTPUT); |
| 53 | + digitalWrite(led, LOW); |
55 | 54 |
|
56 | 55 | // Init button for factory reset
|
57 |
| - pinMode(BUTTON_PIN, INPUT_PULLUP); |
| 56 | + pinMode(button, INPUT_PULLUP); |
58 | 57 |
|
59 | 58 | //Optional: set Zigbee device name and model
|
60 | 59 | zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
|
@@ -82,11 +81,11 @@ void setup() {
|
82 | 81 |
|
83 | 82 | void loop() {
|
84 | 83 | // Checking button for factory reset
|
85 |
| - if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed |
| 84 | + if (digitalRead(button) == LOW) { // Push button pressed |
86 | 85 | // Key debounce handling
|
87 | 86 | delay(100);
|
88 | 87 | int startTime = millis();
|
89 |
| - while (digitalRead(BUTTON_PIN) == LOW) { |
| 88 | + while (digitalRead(button) == LOW) { |
90 | 89 | delay(50);
|
91 | 90 | if ((millis() - startTime) > 3000) {
|
92 | 91 | // If key pressed for more than 3secs, factory reset Zigbee and reboot
|
|
0 commit comments