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/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 + } }