From 2712a0bc4e3eb41d724fbaa6038371ec0a1d4004 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 20 Aug 2020 18:21:03 +0100 Subject: we can sense quite fast! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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! --- esp32/lego-piano.ino | 15 +++++++++++---- 1 file 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 -- cgit v1.2.3