So I've been experimenting with the whole MIDI over USB thing and have been using an accelerometer to control the values. It calculates tilt, converts to a MIDI value scale of 0-127, and finally sends the value over USB. I've also had success with max/mxp reading the values pf the x-axis and sending them to logic pro as a controller.
How would I send not only the x-axis, but the y-axis to control another parameter over USB? This is obviously a misunderstanding in MIDI format, but I could definitely use some help.
int inpin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int groundpin = 18; // analog input pin 4
int powerpin = 19; // analog input pin 5
int xpin = 3; // x-axis of the accelerometer
int ypin = 2; // y-axis
int zpin = 1; // z-axis (only on 3-axis models)
double xval;
double yval;
double zval;
double oxpin = 0; // x-axis origin
double oypin = 0; // y-axis origin
double ozpin = 0; // z-axis origin
byte MIDI_channel = 1;
byte cc_number = 127;
void setup()
{
Serial.begin(9600);
pinMode(inpin, INPUT); // declare pushbutton as input
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
xval = analogRead(xpin);
xval = ((xval*.002929)-1.5)/.3;
xval = asin(xval);
xval = abs((xval*(180/3.14)));
xval = xval*1.411;
midiMsg(channel+0xB0, 10, xval);
}
void midiMsg(byte cmd, byte data1, byte data2)
{
digitalWrite(powerpin,HIGH); // indicate we're sending MIDI data
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
digitalWrite(powerpin,LOW);
}
By the way, I've noticed many people struggling here calculating tilt with the ADXL330. I used the formula:
arcsine(((Vout-Voffset)/Sensitivity))
Vout = your x value * resolution of your A/D converter
resolution of A/D converter = 3/(2^10); 10 being 10-bit
voffset = 1.5V
Sensitivity = .3V
I'm new, but am really excited about the Arduino!