Skip to content

Instantly share code, notes, and snippets.

@AlexLakatos
Created October 21, 2017 12:19
Show Gist options
  • Save AlexLakatos/75531c3f0fc8f6ab53c1a66d5f00c4af to your computer and use it in GitHub Desktop.
Save AlexLakatos/75531c3f0fc8f6ab53c1a66d5f00c4af to your computer and use it in GitHub Desktop.
var kb = require("ble_hid_keyboard");
NRF.setServices(undefined, { hid : kb.report });
var reset_timer;
var next = "n";
var prev = "p";
function sendCharNext(){
if (next == next.toLowerCase()){
sk = 0;
} else {
sk = 0x02;
}
// send the "n" keyboard character
kb.tap(kb.KEY[next.toUpperCase()], sk);
}
function sendCharPrev(){
if (prev == prev.toLowerCase()){
sk = 0;
} else {
sk = 0x02;
}
// send the "p" keyboard character
kb.tap(kb.KEY[prev.toUpperCase()], sk);
}
var single = true;
setWatch(function(e) {
var td = e.time - e.lastTime;
if (td > 0.7 || isNaN(td)) {
single = true;
setTimeout(function() {
if (single){
LED2.set();
setTimeout("LED2.reset()", 1000);
sendCharNext();
}
}, 300);
} else {
LED1.set();
LED3.set();
setTimeout("LED1.reset()", 1000);
setTimeout("LED3.reset()", 1000);
sendCharPrev();
single = false;
}
}, BTN, {
edge: "rising",
debounce: 50,
repeat: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment