Just thought I'd share the finished code for sending a word with a click of the button as a BLE HID Keyboard, not yet tried linking to the RasPi but works great with my iMac
var kb = require("ble_hid_keyboard");
NRF.setServices(undefined, { hid : kb.report });
var reset_timer;
var char_timer;
var arr;
var word = "Hello";
function send(){
LED3.set();
arr = word.split("");
char_timer = setInterval("sendChar()", 100);
LED2.set();
setTimeout("LED2.reset()",1000);
LED3.reset();
}
function onTimeout() {
setTimeout("LED1.reset()",5000);
LED1.set();
LED3.reset();
}
function sendChar(){
if (arr.length !== 0){
var char = arr.shift();
if (char == char.toLowerCase())
{
sk = 0;
}
else
{
sk = 0x02;
}
kb.tap(kb.KEY[char.toUpperCase()], sk);
}
else{
clearInterval(char_timer);
}
}
setWatch(function() {
send();
}, BTN, {edge:"rising", debounce:50, repeat:true});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Just thought I'd share the finished code for sending a word with a click of the button as a BLE HID Keyboard, not yet tried linking to the RasPi but works great with my iMac