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