File tree 1 file changed +23
-2
lines changed 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 12
12
#define ECHO_PIN A0
13
13
#define TRIG_PIN A1
14
14
15
- #define PLAY_DISTANCE 30
15
+ #define PLAY_DISTANCE 75
16
16
#define MODE_LOOPS 3
17
17
#define LOOP_DELAY 50
18
+ #define PLAY_CONFIRMATIONS 10
18
19
#define PLAY_COOLDOWN_DELAY 10000
19
20
20
21
/*
@@ -47,6 +48,7 @@ int _modeLoop = 0;
47
48
bool _loopFinished = false ;
48
49
int _activeLed = -1 ;
49
50
int _activeLedPair = -1 ;
51
+ int _playConfirmation = 0 ;
50
52
51
53
void setup () {
52
54
for (int l = 0 ; l < LED_PIN_NUM; l++) {
@@ -149,13 +151,32 @@ int nextMode() {
149
151
return SINGLE;
150
152
}
151
153
154
+ bool validatePlayConfirmation () {
155
+ if (_playConfirmation < PLAY_CONFIRMATIONS) {
156
+ _playConfirmation++;
157
+ return false ;
158
+ }
159
+
160
+ _playConfirmation = 0 ;
161
+ return true ;
162
+ }
163
+
164
+ void discardPlayConfirmation () {
165
+ _playConfirmation = 0 ;
166
+ }
167
+
152
168
void loop () {
153
169
int distance = calculateDistance ();
154
170
155
171
if (distance < PLAY_DISTANCE and distance > 5 ) {
156
- mode = X_PLAY;
172
+ if (validatePlayConfirmation ()) {
173
+ mode = X_PLAY;
174
+ } else {
175
+ mode = nextMode ();
176
+ }
157
177
} else {
158
178
mode = nextMode ();
179
+ discardPlayConfirmation ();
159
180
}
160
181
161
182
switch (mode) {
You can’t perform that action at this time.
0 commit comments