Memsic2125 - // as inputs: pinMode(xPin, INPUT);...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* 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 This example code is in the public domain. */ // these constants won't change: const int xPin = 2; // X output of the accelerometer const int yPin = 3; // Y output of the accelerometer / void setup() { // initialize serial communications: Serial.begin(9600); // initialize the pins connected to the accelerometer
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // as inputs: pinMode(xPin, INPUT); pinMode(yPin, INPUT); } void loop() { // variables to read the pulse widths: 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; // print the acceleration Serial.print(accelerationX); // print a tab character: Serial.print("\t"); Serial.print(accelerationY); Serial.println(); delay(100); }...
View Full Document

Page1 / 2

Memsic2125 - // as inputs: pinMode(xPin, INPUT);...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online