I have a Mx2125 accelerometer hooked up to my Arduino and am trying to use it in place of the potentiometers on my Cellular Automaton video synth.
I have the accelerometer reading just fine and mapped it to read 0-255.
I have connected the center pin that would normally go to the center pin on the potentiometer to the 9 and 10PWM pins on the Arduino. Below is my code, if anyone have any tips or ideas I would be very happy:
int xpin = 2;
int ypin = 3;
// Digital pin settings
int xOut = 9; // LEDs connected to digital pins 9, 10 and 11
int yOut = 10; // (Connect cathodes to digital ground)
int xVal = 0; // Variables to store the input from the potentiometers
int yVal = 0;
pinMode(xOut, OUTPUT); // sets the digital pins as output
int pulseX, pulseY;
int accX, accY;
// read pulse from x- and y-axes
pulseX = pulseIn(xpin,HIGH);
pulseY = pulseIn(ypin,HIGH);
// convert the pulse width into acceleration
// accX and accY are in milli-g's: earth's gravity is 1000.
accX = map(pulseX, 3700, 6150, 0, 255);
accY = map(pulseY, 3700, 6150, 0, 255);
analogWrite(xOut, xVal); // Send new values to LEDs
// print the acceleration