aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-08-20 18:21:03 +0100
committerdakkar <dakkar@thenautilus.net>2020-08-20 18:22:52 +0100
commit2712a0bc4e3eb41d724fbaa6038371ec0a1d4004 (patch)
tree17dba28b6758da0b6a89cb98d3ead514f1f89b9a
parentlinks for amp (diff)
downloadlego-piano-2712a0bc4e3eb41d724fbaa6038371ec0a1d4004.tar.gz
lego-piano-2712a0bc4e3eb41d724fbaa6038371ec0a1d4004.tar.bz2
lego-piano-2712a0bc4e3eb41d724fbaa6038371ec0a1d4004.zip
we can sense quite fast!
1ms between reads means a full scan of the 5×5 matrix takes ~25ms, so about 40Hz sampling for the entire keyboard. Should be enough!
-rw-r--r--esp32/lego-piano.ino15
1 files changed, 11 insertions, 4 deletions
diff --git a/esp32/lego-piano.ino b/esp32/lego-piano.ino
index 81f75c9..d67a75a 100644
--- a/esp32/lego-piano.ino
+++ b/esp32/lego-piano.ino
@@ -17,6 +17,7 @@
*/
int currentLed = 0;
+int lastSeen = 100;
void setup() {
Serial.begin(19200);
@@ -27,6 +28,7 @@ void setup() {
pinMode(A1, INPUT);
pinMode(A2, INPUT);
currentLed = 0;
+ lastSeen = 100;
}
void tristate(int pin) {
@@ -82,12 +84,17 @@ void loop() {
/* Serial.println(currentLed); */
enableLed(currentLed);
- delay(20);
+ delay(1);
if (sense(currentLed)) {
- Serial.print(currentLed);
- Serial.println(" proximity!");
+ if (lastSeen != currentLed) {
+ lastSeen = currentLed;
+ Serial.print(currentLed);
+ Serial.println(" proximity!");
+ }
+ }
+ else if (lastSeen == currentLed) {
+ lastSeen = 100;
}
currentLed = (currentLed+1)%4;
- delay(20);
} \ No newline at end of file