16
16
* @brief This example demonstrates Zigbee Window Covering.
17
17
*
18
18
* The example demonstrates how to use Zigbee library to create a end device window covering device.
19
- * The window covering is a Zigbee end device, which is moving the blinds (lift+tilt) and reporting
19
+ * The window covering is a Zigbee end device, which is moving the blinds (lift+tilt) and reporting
20
20
* its current position to the Zigbee network.
21
- *
21
+ *
22
22
* Use setCoveringType() to set the type of covering (blind, shade, etc.).
23
- *
23
+ *
24
24
* The example also demonstrates how to use the button to manually control the lift position.
25
25
*
26
26
* Proper Zigbee mode must be selected in Tools->Zigbee mode
38
38
#include " ZigbeeCore.h"
39
39
#include " ep/ZigbeeWindowCovering.h"
40
40
41
-
42
41
#define ZIGBEE_COVERING_ENDPOINT 10
43
- #define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
42
+ #define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
44
43
45
- #define MAX_LIFT 200 // centimeters from open position (0-900)
46
- #define MIN_LIFT 0
44
+ #define MAX_LIFT 200 // centimeters from open position (0-900)
45
+ #define MIN_LIFT 0
47
46
48
- #define MAX_TILT 40 // centimeters from open position (0-900)
49
- #define MIN_TILT 0
47
+ #define MAX_TILT 40 // centimeters from open position (0-900)
48
+ #define MIN_TILT 0
50
49
51
50
uint16_t currentLift = MAX_LIFT;
52
51
uint8_t currentLiftPercentage = 100 ;
@@ -57,7 +56,7 @@ uint8_t currentTiltPercentage = 100;
57
56
ZigbeeWindowCovering zbCovering = ZigbeeWindowCovering(ZIGBEE_COVERING_ENDPOINT);
58
57
59
58
void setup () {
60
- Serial.begin (115200 );
59
+ Serial.begin (115200 );
61
60
62
61
// Init button for factory reset
63
62
pinMode (BUTTON_PIN, INPUT_PULLUP);
@@ -100,7 +99,7 @@ void setup() {
100
99
Serial.print (" ." );
101
100
delay (100 );
102
101
}
103
- Serial.println ();
102
+ Serial.println ();
104
103
105
104
// Set initial position
106
105
zbCovering.setLiftPercentage (currentLiftPercentage);
@@ -124,11 +123,11 @@ void loop() {
124
123
}
125
124
// Manual lift controll simulation by pressing button
126
125
manualControl ();
127
- }
126
+ }
128
127
delay (500 );
129
128
}
130
129
131
- void fullOpen (){
130
+ void fullOpen () {
132
131
/* This is where you would trigger your motor to go to full open state, currentLift should
133
132
be updated until full open has been reached in order to provide feedback to controller of actual position
134
133
The stop can be always called, so the movement can be stopped at any time */
@@ -141,7 +140,7 @@ void fullOpen(){
141
140
zbCovering.setLiftPercentage (currentLiftPercentage);
142
141
}
143
142
144
- void fullClose (){
143
+ void fullClose () {
145
144
/* This is where you would trigger your motor to go to full close state, currentLift should
146
145
be updated until full close has been reached in order to provide feedback to controller of actual position
147
146
The stop can be always called, so the movement can be stopped at any time */
@@ -164,7 +163,7 @@ void goToLiftPercentage(uint8_t liftPercentage) {
164
163
Serial.printf (" New requsted lift from Zigbee: %d (%d)\n " , currentLift, liftPercentage);
165
164
166
165
// Update the current position
167
- zbCovering.setLiftPercentage (currentLiftPercentage); // or setLiftPosition()
166
+ zbCovering.setLiftPercentage (currentLiftPercentage); // or setLiftPosition()
168
167
}
169
168
170
169
void goToTiltPercentage (uint8_t tiltPercentage) {
@@ -177,13 +176,12 @@ void goToTiltPercentage(uint8_t tiltPercentage) {
177
176
Serial.printf (" New requsted tilt from Zigbee: %d (%d)\n " , currentTilt, tiltPercentage);
178
177
179
178
// Update the current position
180
- zbCovering.setTiltPercentage (currentTiltPercentage); // or setTiltPosition()
179
+ zbCovering.setTiltPercentage (currentTiltPercentage); // or setTiltPosition()
181
180
}
182
181
183
-
184
182
void stopMotor () {
185
183
// Motor can be stopped while moving cover toward current target, when stopped the actual position should be updated
186
- Serial.println (" Stopping motor" );
184
+ Serial.println (" Stopping motor" );
187
185
// Update the current position of both lift and tilt
188
186
zbCovering.setLiftPercentage (currentLiftPercentage);
189
187
zbCovering.setTiltPercentage (currentTiltPercentage);
@@ -192,9 +190,9 @@ void stopMotor() {
192
190
void manualControl () {
193
191
// Simulate lift percentage move by increasing it by 20% each time
194
192
currentLiftPercentage += 20 ;
195
- if (currentLiftPercentage > 100 ) {
193
+ if (currentLiftPercentage > 100 ) {
196
194
currentLiftPercentage = 0 ;
197
195
}
198
196
zbCovering.setLiftPercentage (currentLiftPercentage);
199
197
// Also setLiftPosition() can be used to set the exact position instead of percentage
200
- }
198
+ }
0 commit comments