Created
October 21, 2017 12:19
-
-
Save AlexLakatos/75531c3f0fc8f6ab53c1a66d5f00c4af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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