Update Zigbee_On_Off_Light.ino
This commit is contained in:
@@ -32,29 +32,28 @@
|
||||
|
||||
#include "Zigbee.h"
|
||||
|
||||
#define LED_PIN RGB_BUILTIN
|
||||
#define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
|
||||
/* Zigbee light bulb configuration */
|
||||
#define ZIGBEE_LIGHT_ENDPOINT 10
|
||||
uint8_t led = RGB_BUILTIN;
|
||||
uint8_t button = BOOT_PIN;
|
||||
|
||||
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
|
||||
|
||||
/********************* RGB LED functions **************************/
|
||||
void setLED(bool value) {
|
||||
digitalWrite(LED_PIN, value);
|
||||
digitalWrite(led, value);
|
||||
}
|
||||
|
||||
/********************* Arduino functions **************************/
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
pinMode(led, OUTPUT);
|
||||
digitalWrite(led, LOW);
|
||||
|
||||
// Init button for factory reset
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(button, INPUT_PULLUP);
|
||||
|
||||
//Optional: set Zigbee device name and model
|
||||
zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
|
||||
@@ -82,11 +81,11 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// Checking button for factory reset
|
||||
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
|
||||
if (digitalRead(button) == LOW) { // Push button pressed
|
||||
// Key debounce handling
|
||||
delay(100);
|
||||
int startTime = millis();
|
||||
while (digitalRead(BUTTON_PIN) == LOW) {
|
||||
while (digitalRead(button) == LOW) {
|
||||
delay(50);
|
||||
if ((millis() - startTime) > 3000) {
|
||||
// If key pressed for more than 3secs, factory reset Zigbee and reboot
|
||||
|
||||
Reference in New Issue
Block a user