aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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