1616 * @brief This example demonstrates Zigbee Window Covering.
1717 *
1818 * 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
2020 * its current position to the Zigbee network.
21- *
21+ *
2222 * Use setCoveringType() to set the type of covering (blind, shade, etc.).
23- *
23+ *
2424 * The example also demonstrates how to use the button to manually control the lift position.
2525 *
2626 * Proper Zigbee mode must be selected in Tools->Zigbee mode
3838#include " ZigbeeCore.h"
3939#include " ep/ZigbeeWindowCovering.h"
4040
41-
4241#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
4443
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
4746
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
5049
5150uint16_t currentLift = MAX_LIFT;
5251uint8_t currentLiftPercentage = 100 ;
@@ -57,7 +56,7 @@ uint8_t currentTiltPercentage = 100;
5756ZigbeeWindowCovering zbCovering = ZigbeeWindowCovering(ZIGBEE_COVERING_ENDPOINT);
5857
5958void setup () {
60- Serial.begin (115200 );
59+ Serial.begin (115200 );
6160
6261 // Init button for factory reset
6362 pinMode (BUTTON_PIN, INPUT_PULLUP);
@@ -100,7 +99,7 @@ void setup() {
10099 Serial.print (" ." );
101100 delay (100 );
102101 }
103- Serial.println ();
102+ Serial.println ();
104103
105104 // Set initial position
106105 zbCovering.setLiftPercentage (currentLiftPercentage);
@@ -124,11 +123,11 @@ void loop() {
124123 }
125124 // Manual lift controll simulation by pressing button
126125 manualControl ();
127- }
126+ }
128127 delay (500 );
129128}
130129
131- void fullOpen (){
130+ void fullOpen () {
132131 /* This is where you would trigger your motor to go to full open state, currentLift should
133132 be updated until full open has been reached in order to provide feedback to controller of actual position
134133 The stop can be always called, so the movement can be stopped at any time */
@@ -141,7 +140,7 @@ void fullOpen(){
141140 zbCovering.setLiftPercentage (currentLiftPercentage);
142141}
143142
144- void fullClose (){
143+ void fullClose () {
145144 /* This is where you would trigger your motor to go to full close state, currentLift should
146145 be updated until full close has been reached in order to provide feedback to controller of actual position
147146 The stop can be always called, so the movement can be stopped at any time */
@@ -164,7 +163,7 @@ void goToLiftPercentage(uint8_t liftPercentage) {
164163 Serial.printf (" New requsted lift from Zigbee: %d (%d)\n " , currentLift, liftPercentage);
165164
166165 // Update the current position
167- zbCovering.setLiftPercentage (currentLiftPercentage); // or setLiftPosition()
166+ zbCovering.setLiftPercentage (currentLiftPercentage); // or setLiftPosition()
168167}
169168
170169void goToTiltPercentage (uint8_t tiltPercentage) {
@@ -177,13 +176,12 @@ void goToTiltPercentage(uint8_t tiltPercentage) {
177176 Serial.printf (" New requsted tilt from Zigbee: %d (%d)\n " , currentTilt, tiltPercentage);
178177
179178 // Update the current position
180- zbCovering.setTiltPercentage (currentTiltPercentage); // or setTiltPosition()
179+ zbCovering.setTiltPercentage (currentTiltPercentage); // or setTiltPosition()
181180}
182181
183-
184182void stopMotor () {
185183 // 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" );
187185 // Update the current position of both lift and tilt
188186 zbCovering.setLiftPercentage (currentLiftPercentage);
189187 zbCovering.setTiltPercentage (currentTiltPercentage);
@@ -192,9 +190,9 @@ void stopMotor() {
192190void manualControl () {
193191 // Simulate lift percentage move by increasing it by 20% each time
194192 currentLiftPercentage += 20 ;
195- if (currentLiftPercentage > 100 ) {
193+ if (currentLiftPercentage > 100 ) {
196194 currentLiftPercentage = 0 ;
197195 }
198196 zbCovering.setLiftPercentage (currentLiftPercentage);
199197 // Also setLiftPosition() can be used to set the exact position instead of percentage
200- }
198+ }
0 commit comments