#include int t = 0; /* Memsic2125 Read the Memsic 2125 two-axis accelerometer. Converts the pulses output by the 2125 into milli-g's (1/1000 of earth's gravity) and prints them over the serial connection to the computer. The circuit: * X output of accelerometer to digital pin 2 * Y output of accelerometer to digital pin 3 * +V of accelerometer to +5V * GND of accelerometer to ground http://www.arduino.cc/en/Tutorial/Memsic2125 created 6 Nov 2008 by David A. Mellis modified 30 Jun 2009 by Tom Igoe */ int special = 0; int q = 120; int m2 = 0; // these constants won't change: const int xPin = 2; // X output of the accelerometer const int yPin = 3; // Y output of the accelerometer int m = 0; void setup() { // initialize serial communications: MIDI.begin(4); Serial.begin(9600); // initialize the pins connected to the accelerometer // as inputs: pinMode(xPin, INPUT); pinMode(yPin, INPUT); for (int i = 1; i < 17; i++){ pinMode(42 - i, OUTPUT); Serial.println(42 - i); } Serial.println("setup complete"); Serial.begin(31250); } void loop() { for (int i = 1; i < 17; i++){ int pulseX, pulseY; // variables to contain the resulting accelerations int accelerationX, accelerationY; // read pulse from x- and y-axes: pulseX = pulseIn(xPin,HIGH); pulseY = pulseIn(yPin,HIGH); // convert the pulse width into acceleration // accelerationX and accelerationY are in milli-g's: // earth's gravity is 1000 milli-g's, or 1g. accelerationX = ((pulseX / 10) - 500) * 8; accelerationY = ((pulseY / 10) - 500) * 8; int absX = abs(accelerationX); int absY = abs(accelerationY); digitalWrite(42 - i, HIGH); delay(10); int analog0 = analogRead(0); digitalWrite(42 - i,LOW); if ((analog0 > 650) and (analog0 < 850)) { m2 = m; m = 62; } if ((analog0 > 500) and (analog0 < 651)) { m2 = m; m = 60; } if ((analog0 > 400) and (analog0 < 501)) { m2 = m; m = 58; } if ((analog0 > 300) and (analog0 < 401)) { m2 = m; m = 57; } if ((analog0 > 100) and (analog0 < 301)) { m2 = m; m = 56; } if ((analog0 > 70) and (analog0 < 101)) { m2 = m; m = 54; } if ((analog0 > 65) and (analog0 < 71)) { m2 = m; m = 52; } if ((analog0 > 60) and (analog0 < 66)) { m2 = m; m = 51; } if ((analog0 > 55) and (analog0 < 61)) { m2 = m; m = 49; } if ((analog0 > 50) and (analog0 < 56)) { m2 = m; m = 47; } if ((analog0 > 45) and (analog0 < 51)) { m2 = m; m = 45; } if ((analog0 > 40) and (analog0 < 46)) { m2 = m; m = 44; } if ((analog0 > 35) and (analog0 < 41)) { m2 = m; m = 42; } if ((analog0 > 25) and (analog0 < 36)) { m2 = m; m = 40; } if (analog0 > 850) { m2 = m; m = m2 + 12; } m = m + (accelerationY/100); MIDI.sendNoteOff(m2,0,1); MIDI.sendNoteOn(m,q,1); if ((accelerationX > -990) and (accelerationX < 3000)){ delay(1000 + accelerationX); } else{ delay(1000); } // variables to read the pulse widths: } }