Skip to content

Commit 9ec2f9b

Browse files
committed
feature(open): Open for longer times, if requested
1 parent b178b09 commit 9ec2f9b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

basurito/basurito.ino

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ int srvPos = SRV_CLOSED;
1818
#define TRIG_PIN 3
1919
#define ECHO_PIN 4
2020

21-
#define MAX_DIST 80
21+
#define MAX_DIST 60
2222
#define MIN_DIST 25
2323

24+
#define MAX_LONG_DIST 90
25+
#define MIN_LONG_DIST 61
26+
2427
int distance;
2528

2629
bool isOpen = false;
2730
bool isManual = false;
2831
bool isOpening = false;
2932
bool isClosing = false;
3033

34+
bool isOpenForLong = false;
35+
3136
bool isMoving() {
3237
return isOpening || isClosing;
3338
}
@@ -87,9 +92,17 @@ void loop() {
8792
if (distance >= MIN_DIST and distance <= MAX_DIST) {
8893
isOpening = true;
8994
isManual = false;
95+
isOpenForLong = false;
9096
} 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+
}
93106
}
94107
}
95108

@@ -142,7 +155,13 @@ void loop() {
142155

143156
// After being open automatically (by sensor trigger), sleep and signal opening again ;)
144157
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+
}
146165
isOpen = false;
147166
isClosing = true;
148167
}

0 commit comments

Comments
 (0)