Skip to content

Commit 50981bb

Browse files
authored
Possible fix for incorrect SELECT detect
The `LEFT` key is close in the analog range to `SELECT` so quick presses of `LEFT` could be detected as `SELECT`. Added sampling and changed the range check.
1 parent 3589162 commit 50981bb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

MRSC/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ namespace Keypad {
7676
uint16_t adc;
7777

7878
do {
79-
adc = analogRead(KEYPAD_PIN);
79+
adc = 0;
80+
for (uint8_t i = 0; i < 5; i++) {
81+
adc += analogRead(KEYPAD_PIN);
82+
delay(5);
83+
}
84+
adc /= 5;
85+
8086
if (adc < 50) {
8187
key = Key::RIGHT;
8288
} else if (adc < 250) {
@@ -85,7 +91,7 @@ namespace Keypad {
8591
key = Key::DOWN;
8692
} else if (adc < 650) {
8793
key = Key::LEFT;
88-
} else if (adc < 850) {
94+
} else if (adc > 800 && adc < 850) {
8995
key = Key::SELECT;
9096
}
9197
} while (blocking && adc < 1000);

0 commit comments

Comments
 (0)