@@ -18,16 +18,21 @@ int srvPos = SRV_CLOSED;
18
18
#define TRIG_PIN 3
19
19
#define ECHO_PIN 4
20
20
21
- #define MAX_DIST 80
21
+ #define MAX_DIST 60
22
22
#define MIN_DIST 25
23
23
24
+ #define MAX_LONG_DIST 90
25
+ #define MIN_LONG_DIST 61
26
+
24
27
int distance;
25
28
26
29
bool isOpen = false ;
27
30
bool isManual = false ;
28
31
bool isOpening = false ;
29
32
bool isClosing = false ;
30
33
34
+ bool isOpenForLong = false ;
35
+
31
36
bool isMoving () {
32
37
return isOpening || isClosing;
33
38
}
@@ -87,9 +92,17 @@ void loop() {
87
92
if (distance >= MIN_DIST and distance <= MAX_DIST) {
88
93
isOpening = true ;
89
94
isManual = false ;
95
+ isOpenForLong = false ;
90
96
} else {
91
- // ... if not, just sleep waiting for the better times ...
92
- LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF);
97
+ // special case: holding your hand at the longer distance may cause longer open time
98
+ if (distance >= MIN_LONG_DIST and distance <= MAX_LONG_DIST) {
99
+ isOpening = true ;
100
+ isManual = false ;
101
+ isOpenForLong = true ;
102
+ } else {
103
+ // ... if not, just sleep waiting for the better times ...
104
+ LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF);
105
+ }
93
106
}
94
107
}
95
108
@@ -142,7 +155,13 @@ void loop() {
142
155
143
156
// After being open automatically (by sensor trigger), sleep and signal opening again ;)
144
157
if (isAutoOpen ()) {
145
- LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF);
158
+ if (!isOpenForLong) {
159
+ LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF);
160
+ } else {
161
+ for (int c = 0 ; c < 10 ; c++) {
162
+ LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF);
163
+ }
164
+ }
146
165
isOpen = false ;
147
166
isClosing = true ;
148
167
}
0 commit comments