espruino / EspruinoDocs

See http://espruino.com for the complete Espruino Documentation - many links in this repository will not work
http://www.espruino.com/
Other
253 stars 282 forks source link

Add onWrite to ble_midi.js #690

Closed joebowbeer closed 1 year ago

joebowbeer commented 1 year ago

Changes:

I tested this with a simple program that receives note events and echoes the same events a 5th higher.

var midi = require('https://raw.githubusercontent.com/joebowbeer/EspruinoDocs/patch-1/modules/ble_midi.js');
midi.init();

midi.on('midi', function(data) {
  var cmd = data[2] & 0xF0; // command
  var chn = data[2] & 0x0F; // channel
  switch(cmd) {
    case 0x80: // noteOff
    case 0x90: // noteOn
      var num = data[3];
      var val = data[4];
      if (val) LED3.set(); else LED3.reset();
      midi.cmd(cmd+chn, num+7, val);
      break;
  }
});
gfwilliams commented 1 year ago

Great, thanks! I'll add that example to the markdown file as well