Hello, I am trying to send the accelerometer angles as midi cc when a button is being pushed.
But I am struggling getting the accelerometer data separately. Any help is welcome!
thank you!
// Include the MIDI library
NRF.setServices({
0x180D: {
0x2A37: {
value : [0],
writable : true
}
}
}, { advertise: ['180D'] });
// Set up the button pin
var BUTTON_PIN = BTN;
pinMode(BUTTON_PIN, "input_pullup");
// Set up the accelerometer
var accel = require("puckjsv2-accel").use({
frequency: 10,
samples: 10
});
// Function to send accelerometer data as MIDI CC values
function sendAccelerometerData() {
// Get the accelerometer data
var data = accel.get();
// Send MIDI CC messages for each axis
MIDI.send([0xB0, 1, data.x >> 3]);
MIDI.send([0xB0, 2, data.y >> 3]);
MIDI.send([0xB0, 3, data.z >> 3]);
}
// Set up a timer to continuously send accelerometer data
var sendTimer = null;
function startSending() {
sendTimer = setInterval(function() {
sendAccelerometerData();
}, 50);
}
function stopSending() {
clearInterval(sendTimer);
}
// Set up button events to start and stop sending
setWatch(function(e) {
if (e.state == false) {
// Button was released, stop sending
stopSending();
} else {
// Button was pressed, start sending
startSending();
}
}, BUTTON_PIN, { edge: "both", 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.
Hello, I am trying to send the accelerometer angles as midi cc when a button is being pushed.
But I am struggling getting the accelerometer data separately. Any help is welcome!
thank you!