Skip to content

Commit

Permalink
merge debounce, resolve changes between dugbraden & michealfriesen
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-inksmith committed Oct 21, 2021
2 parents 0b2bc10 + d3c9b4c commit c26d6fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _locales/es/cak-strings.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
}
}

0 comments on commit c26d6fc

Please sign in to comment.