hi,
I am trying to send midi cc only on motion detection, but I get nothing coming and the terminl issue me an error: WARNING: SD ERR 0x11 (BUSY) (:835)
I am using require("puckjsv2-accel-movement").on(); and suspect I am using setservices twice then which could be the problem? but not really sure where to look at.
here is the code:
require("puckjsv2-accel-movement").on();
/// Sends a raw MIDI command
function cmd(cmd, d1, d2) {
NRF.updateServices({
"03B80E5A-EDE8-4B33-A751-6CE34EC4C700": {
"7772E5DB-3868-4112-A1A9-F2669D106BF3": {
value: [0x80, 0x80, cmd, d1, d2],
notify: true
}
}
});
}
/// Send a 'control change' (0xB0) MIDI command
function midisend(channel, controller, value) { cmd(0xB0+channel,controller,value); }
function rescaleToMidiCC(value, oldMin, oldMax) {
var newMin = 0;
var newMax = 127;
var rescaled = Math.round((value - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin);
rescaled = Math.min(127, Math.max(0, rescaled));
return rescaled;
}
/// Turns the device into a MIDI controller
function init(name) {
//NRF.setSecurity({passkey:"123456", lesc:1, bond :1});
NRF.setServices({
"03B80E5A-EDE8-4B33-A751-6CE34EC4C700": { // MIDI
"7772E5DB-3868-4112-A1A9-F2669D106BF3": {
readable: true,
writable: true,
notify: true,
value: [0x80, 0x80, 0x00, 0x00, 0x00]
}
}
});
NRF.setAdvertising([
// Flags: LE Limited Discoverable Mode, BR/EDR Not Supported
0x02, 0x01, 0x05,
// Complete Local Name: PuckCC
0x07, 0x09,
name.charCodeAt(0),
name.charCodeAt(1),
name.charCodeAt(2),
name.charCodeAt(3),
name.charCodeAt(4),
name.charCodeAt(5),
// MIDI
0x11, 0x06, 0x00, 0xC7, 0xC4, 0x4E, 0xE3, 0x6C, 0x51,
0xA7, 0x33, 0x4B, 0xE8, 0xED, 0x5A, 0x0E, 0xB8, 0x03
]);
//NRF.startBonding(true);
//NRF.setConnectionInterval(20);
NRF.setTxPower(4);
}
init("PuckOI");
var idleTimeout;
var active;
Puck.on('accel',function(a) {
LED.set();
active = true ;
if (idleTimeout) clearTimeout(idleTimeout);
idleTimeout = setTimeout(function() {
idleTimeout = undefined;
LED.reset();
active = false ;
},1000);
});
if (active) {
print("yes");
//Puck.accelOn(); // default is 12.5Hz, with gyro
//Puck.accelOn(1.6);// for 1.6Hz low power, without gyro
// Turn events off with Puck.accelOff();
const accel = Puck.accel();
var x = ((accel.acc.x/128000)*10) *127;
var y = ((accel.acc.y/128000)*10) *127;
x = rescaleToMidiCC(x, -80, 80);
y = rescaleToMidiCC(y, -80, 80);
midisend(0,1,x);
midisend(0,2,y);
}
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.
hi,
I am trying to send midi cc only on motion detection, but I get nothing coming and the terminl issue me an error: WARNING: SD ERR 0x11 (BUSY) (:835)
I am using require("puckjsv2-accel-movement").on(); and suspect I am using setservices twice then which could be the problem? but not really sure where to look at.
here is the code: