From 008475213a7c11e8233dafae3465dec30a4ce566 Mon Sep 17 00:00:00 2001 From: rweir Date: Thu, 5 Aug 2021 13:11:55 -0400 Subject: [PATCH 1/2] Revert "Formatting fix" This reverts commit 19b13d4fd820c4e117293864ebfe3173c230d69a. --- _locales/es/cak-strings.json | 2 +- pxt.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 _locales/es/cak-strings.json diff --git a/_locales/es/cak-strings.json b/_locales/es/cak-strings.json old mode 100644 new mode 100755 index 13b9cdc..40cae4a --- a/_locales/es/cak-strings.json +++ b/_locales/es/cak-strings.json @@ -32,7 +32,7 @@ "servos|block": "servos", "soil.displayMoisture|block": "mostrar nivel de humedad en %pin", "soil.getMoisture|block": "nivel de humedad en pin $pin", - "soil.ifMoisture|block": "activar nivel de humedad en $pin está abajo %mlevel", + "soil.ifMoisture|block": "activar nivel de humedad en $pin está abajo $mlevel", "soil|block": "suelo", "touch.getTouch|block": "encender contacto en $pin", "touch|block": "contacto", diff --git a/pxt.json b/pxt.json index 58d734f..0dfd8d9 100644 --- a/pxt.json +++ b/pxt.json @@ -24,5 +24,5 @@ ], "public": true, "preferredEditor": "tsprj", - "installedVersion": "workspace:aa91a00c-8dbf-498e-7851-e36c6f36a6ad" -} \ No newline at end of file + "installedVersion": "workspace:4fad43cb-1051-43cf-4e95-0dd5d08977c0" +} From d3c9b4c47675a7fc1a9d73845a487a30d56306ef Mon Sep 17 00:00:00 2001 From: rweir Date: Thu, 5 Aug 2021 16:52:03 -0400 Subject: [PATCH 2/2] added getTap which works like a latch so that a new button press won't register until it's been released. Relabelled getTouch to clarify the difference --- touch.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/touch.ts b/touch.ts index 5b0183a..3ebdb1d 100644 --- a/touch.ts +++ b/touch.ts @@ -9,6 +9,9 @@ namespace touch { P12 } + // array of currently latched pins. Push to latch, remove to unlatch + let latchClosed: TouchPin[] = []; + /** * Function used to return actual DigitalPin from enum */ @@ -38,4 +41,25 @@ namespace touch { return false } } + + /** + * Debounced touch control, using flip-flop logic. + */ + //% block="tap at $pin" + export function getTap(pin: TouchPin): boolean { + let pinStatus = getTouch(pin); + let latchStatus = latchClosed.some(p => p == pin); + // Push to latch, remove to unlatch + + if (pinStatus && !latchStatus) { + // touch and unlatched: register touch, close latch + latchClosed.push(pin); + return true; + } else if (!pinStatus && latchStatus) { + // no touch and latched: register no touch, open latch + latchClosed = latchClosed.filter(p => p != pin); + } + return false; + // touch on closed latch, or no touch: register no touch + } }