implementing an xy midi controller using arduino and accelerometer
for anyone that uses cakewalk synths that can use xy controllers like rapture and z3ta+ +2, or any synth via cc mapping, here's how to turn an accelerometer connected to an arduino into a midi controller. X values are mapped to cc16 and Y values are mapped to cc17.
You'll need hairless midi
http://projectgus.github.io/hairless-midiserial/loopmidi
http://www.tobias-erichsen.de/software/loopmidi.htmlan arduino with an accelerometer - these may be calibrated differently, so plop your min and max ranges in the
bold, italicized values.
upload code to ardiono
run loopmidi and make a virtual midi port
run sonar
load rapture
set its input to the loopmidi virtual port
open the xy controller pane and midi learn to your accelerometer
map the xy controls to parameters in your patch
move around the accelerometer for endless fun!
video here:
https://www.youtube.com/watch?v=eEnly2KNPiI&feature=youtu.be Arduino code::
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// set up pin numbers to use for x and y
const int x = 0;
const int y = 1;
//initialize all xy variables
//raw input variables
int xin = 0;
int yin = 0;
//filtered xy cc variables
int xcc = 1;
int ycc = 1;
//midpoints of calibrated accelerometer as initial values
int xfilt = 320;
int yfilt = 320;
//time constant for filter calculations
double ktime = .95;
void setup() {
// initialize midi communication and baud rate
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(38400);
}
void loop() {
// read the analog inputs from the accelerometer
xin = analogRead(x);
yin = analogRead(y);
//apply the smoothing filters
xfilt = ktime * xfilt + (1.0 - ktime) * xin;
yfilt = ktime * yfilt + (1.0 - ktime) * yin;
//map the results to midi range 0-127
xcc = map(constrain(xfilt,
287,371),
287,371,0,127);
ycc = map(constrain(yfilt,
287,371),
287,371,0,127);
//due to a minor bug with cc sends in arduino midi library you need to send each cc twice on different channels
//x is sent on cc16 y is sent on cc17
MIDI.sendControlChange(16,xcc,1);
MIDI.sendControlChange(16,xcc,2);
MIDI.sendControlChange(17,ycc,1);
MIDI.sendControlChange(17,ycc,2);
//wait 6 milliseconds
delay(6);
}
post edited by swamptooth - 2015/02/10 01:33:10