Skip to content

Commit a281b26

Browse files
committed
fix(zigbee): Move button and led pins from defines
1 parent 87d988f commit a281b26

File tree

7 files changed

+45
-39
lines changed

7 files changed

+45
-39
lines changed

Diff for: libraries/Zigbee/examples/Zigbee_Color_Dimmable_Light/Zigbee_Color_Dimmable_Light.ino

+12-11
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@
3333

3434
#include "Zigbee.h"
3535

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;
3940

40-
ZigbeeColorDimmableLight zbColorLight = ZigbeeColorDimmableLight(ZIGBEE_LIGHT_ENDPOINT);
41+
ZigbeeColorDimmableLight zbColorLight = ZigbeeColorDimmableLight(ZIGBEE_RGB_LIGHT_ENDPOINT);
4142

4243
/********************* RGB LED functions **************************/
4344
void setRGBLight(bool state, uint8_t red, uint8_t green, uint8_t blue, uint8_t level) {
4445
if (!state) {
45-
rgbLedWrite(LED_PIN, 0, 0, 0);
46+
rgbLedWrite(led, 0, 0, 0);
4647
return;
4748
}
4849
float brightness = (float)level / 255;
49-
rgbLedWrite(LED_PIN, red * brightness, green * brightness, blue * brightness);
50+
rgbLedWrite(led, red * brightness, green * brightness, blue * brightness);
5051
}
5152

5253
// Create a task on identify call to handle the identify function
@@ -58,7 +59,7 @@ void identify(uint16_t time) {
5859
zbColorLight.restoreLight();
5960
return;
6061
}
61-
rgbLedWrite(LED_PIN, 255 * blink, 255 * blink, 255 * blink);
62+
rgbLedWrite(led, 255 * blink, 255 * blink, 255 * blink);
6263
blink = !blink;
6364
}
6465

@@ -70,10 +71,10 @@ void setup() {
7071
}
7172

7273
// Init RMT and leave light OFF
73-
rgbLedWrite(LED_PIN, 0, 0, 0);
74+
rgbLedWrite(led, 0, 0, 0);
7475

7576
// Init button for factory reset
76-
pinMode(BUTTON_PIN, INPUT_PULLUP);
77+
pinMode(button, INPUT_PULLUP);
7778

7879
// Set callback function for light change
7980
zbColorLight.onLightChange(setRGBLight);
@@ -104,11 +105,11 @@ void setup() {
104105

105106
void loop() {
106107
// Checking button for factory reset
107-
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
108+
if (digitalRead(button) == LOW) { // Push button pressed
108109
// Key debounce handling
109110
delay(100);
110111
int startTime = millis();
111-
while (digitalRead(BUTTON_PIN) == LOW) {
112+
while (digitalRead(button) == LOW) {
112113
delay(50);
113114
if ((millis() - startTime) > 3000) {
114115
// If key pressed for more than 3secs, factory reset Zigbee and reboot

Diff for: libraries/Zigbee/examples/Zigbee_Color_Dimmer_Switch/Zigbee_Color_Dimmer_Switch.ino

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737

3838
#include "Zigbee.h"
3939

40-
/* Switch configuration */
41-
#define SWITCH_PIN 9 // ESP32-C6/H2 Boot button
40+
/* Zigbee color dimmer switch configuration */
4241
#define SWITCH_ENDPOINT_NUMBER 5
42+
uint8_t button = BOOT_PIN;
4343

4444
/* Zigbee switch */
4545
ZigbeeColorDimmerSwitch zbSwitch = ZigbeeColorDimmerSwitch(SWITCH_ENDPOINT_NUMBER);
@@ -52,7 +52,7 @@ void setup() {
5252
}
5353

5454
//Init button switch
55-
pinMode(SWITCH_PIN, INPUT_PULLUP);
55+
pinMode(button, INPUT_PULLUP);
5656

5757
//Optional: set Zigbee device name and model
5858
zbSwitch.setManufacturerAndModel("Espressif", "ZigbeeSwitch");
@@ -84,9 +84,9 @@ void setup() {
8484

8585
void loop() {
8686
// Handle button switch in loop()
87-
if (digitalRead(SWITCH_PIN) == LOW) { // Push button pressed
87+
if (digitalRead(button) == LOW) { // Push button pressed
8888
// Key debounce handling
89-
while (digitalRead(SWITCH_PIN) == LOW) {
89+
while (digitalRead(button) == LOW) {
9090
delay(50);
9191
}
9292
// Toggle light
@@ -145,6 +145,6 @@ void loop() {
145145
static uint32_t last_print = 0;
146146
if (millis() - last_print > 30000) {
147147
last_print = millis();
148-
zbSwitch.printBoundDevices(Serial);
148+
zbSwitch.printBoundDevices();
149149
}
150150
}

Diff for: libraries/Zigbee/examples/Zigbee_On_Off_Light/Zigbee_On_Off_Light.ino

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232

3333
#include "Zigbee.h"
3434

35-
#define LED_PIN RGB_BUILTIN
36-
#define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
35+
/* Zigbee light bulb configuration */
3736
#define ZIGBEE_LIGHT_ENDPOINT 10
37+
uint8_t led = RGB_BUILTIN;
38+
uint8_t button = BOOT_PIN;
3839

3940
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
4041

4142
/********************* RGB LED functions **************************/
4243
void setLED(bool value) {
43-
digitalWrite(LED_PIN, value);
44+
digitalWrite(led, value);
4445
}
4546

4647
/********************* Arduino functions **************************/
@@ -50,11 +51,11 @@ void setup() {
5051
delay(10);
5152
}
5253
// 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);
54+
pinMode(led, OUTPUT);
55+
digitalWrite(led, LOW);
5556

5657
// Init button for factory reset
57-
pinMode(BUTTON_PIN, INPUT_PULLUP);
58+
pinMode(button, INPUT_PULLUP);
5859

5960
//Optional: set Zigbee device name and model
6061
zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
@@ -82,11 +83,11 @@ void setup() {
8283

8384
void loop() {
8485
// Checking button for factory reset
85-
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
86+
if (digitalRead(button) == LOW) { // Push button pressed
8687
// Key debounce handling
8788
delay(100);
8889
int startTime = millis();
89-
while (digitalRead(BUTTON_PIN) == LOW) {
90+
while (digitalRead(button) == LOW) {
9091
delay(50);
9192
if ((millis() - startTime) > 3000) {
9293
// If key pressed for more than 3secs, factory reset Zigbee and reboot

Diff for: libraries/Zigbee/examples/Zigbee_On_Off_Switch/Zigbee_On_Off_Switch.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333

3434
#include "Zigbee.h"
3535

36+
/* Zigbee switch configuration */
3637
#define SWITCH_ENDPOINT_NUMBER 5
3738

38-
/* Switch configuration */
39-
#define GPIO_INPUT_IO_TOGGLE_SWITCH 9
39+
#define GPIO_INPUT_IO_TOGGLE_SWITCH BOOT_PIN
4040
#define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0]))
4141

4242
typedef enum {

Diff for: libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232

3333
#include "Zigbee.h"
3434

35-
#define BUTTON_PIN 9 //Boot button for C6/H2
35+
/* Zigbee temperature + humidity sensor configuration */
3636
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
3737

3838
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
3939
#define TIME_TO_SLEEP 55 /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */
4040

41+
uint8_t button = BOOT_PIN;
42+
4143
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
4244

4345
/************************ Temp sensor *****************************/
@@ -70,7 +72,7 @@ void setup() {
7072
delay(10);
7173
}
7274
// Init button switch
73-
pinMode(BUTTON_PIN, INPUT_PULLUP);
75+
pinMode(button, INPUT_PULLUP);
7476

7577
// Configure the wake up source and set to wake up every 5 seconds
7678
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
@@ -118,11 +120,11 @@ void setup() {
118120

119121
void loop() {
120122
// Checking button for factory reset
121-
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
123+
if (digitalRead(button) == LOW) { // Push button pressed
122124
// Key debounce handling
123125
delay(100);
124126
int startTime = millis();
125-
while (digitalRead(BUTTON_PIN) == LOW) {
127+
while (digitalRead(button) == LOW) {
126128
delay(50);
127129
if ((millis() - startTime) > 3000) {
128130
// If key pressed for more than 3secs, factory reset Zigbee and reboot

Diff for: libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232

3333
#include "Zigbee.h"
3434

35-
#define BUTTON_PIN 9 //Boot button for C6/H2
35+
/* Zigbee temperature sensor configuration */
3636
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
37+
uint8_t button = BOOT_PIN;
3738

3839
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
3940

@@ -56,7 +57,7 @@ void setup() {
5657
delay(10);
5758
}
5859
// Init button switch
59-
pinMode(BUTTON_PIN, INPUT_PULLUP);
60+
pinMode(button, INPUT_PULLUP);
6061

6162
// Optional: set Zigbee device name and model
6263
zbTempSensor.setManufacturerAndModel("Espressif", "ZigbeeTempSensor");
@@ -99,11 +100,11 @@ void setup() {
99100

100101
void loop() {
101102
// Checking button for factory reset
102-
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
103+
if (digitalRead(button) == LOW) { // Push button pressed
103104
// Key debounce handling
104105
delay(100);
105106
int startTime = millis();
106-
while (digitalRead(BUTTON_PIN) == LOW) {
107+
while (digitalRead(button) == LOW) {
107108
delay(50);
108109
if ((millis() - startTime) > 3000) {
109110
// If key pressed for more than 3secs, factory reset Zigbee and reboot

Diff for: libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
#include "Zigbee.h"
3535

36-
#define BUTTON_PIN 9 // Boot button for C6/H2
36+
/* Zigbee thermostat configuration */
3737
#define THERMOSTAT_ENDPOINT_NUMBER 5
38+
uint8_t button = BOOT_PIN;
3839

3940
ZigbeeThermostat zbThermostat = ZigbeeThermostat(THERMOSTAT_ENDPOINT_NUMBER);
4041

@@ -64,7 +65,7 @@ void setup() {
6465
}
6566

6667
// Init button switch
67-
pinMode(BUTTON_PIN, INPUT_PULLUP);
68+
pinMode(button, INPUT_PULLUP);
6869

6970
// Set callback functions for temperature and configuration receive
7071
zbThermostat.onTempRecieve(recieveSensorTemp);
@@ -100,10 +101,10 @@ void setup() {
100101

101102
void loop() {
102103
// Handle button switch in loop()
103-
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
104+
if (digitalRead(button) == LOW) { // Push button pressed
104105

105106
// Key debounce handling
106-
while (digitalRead(BUTTON_PIN) == LOW) {
107+
while (digitalRead(button) == LOW) {
107108
delay(50);
108109
}
109110

0 commit comments

Comments
 (0)