1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-12 23:08:52 +01:00
Arduino/build/shared/examples/Sensors/Memsic2125/Memsic2125.pde
David A. Mellis 2fa8deb92d First integration of the Arduino code in Processing 5503: PreProcessor and Compiler have been integrated with changes to the Sketch.
Compilation still has problems (Thread error on success, and can't handle non-pde files in a sketch).
Modified the Mac OS X make.sh to copy the hardware, avr tools, and example over.
Removing some of the antlr stuff.  
Disabling the Commander (command-line execution) for now.
Added Library, LibraryManager, and Target.
Added support for prefixed preferences (e.g. for boards and programmers).
2009-06-01 08:32:11 +00:00

44 lines
865 B
Plaintext

/*
* 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.
*
* http://www.arduino.cc/en/Tutorial/Memsic2125
*/
int xpin = 2;
int ypin = 3;
void setup()
{
Serial.begin(9600);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
}
void loop()
{
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 = ((pulseX / 10) - 500) * 8;
accY = ((pulseY / 10) - 500) * 8;
// print the acceleration
Serial.print(accX);
Serial.print(" ");
Serial.print(accY);
Serial.println();
delay(100);
}