1. Jody McAdams
  2. ArduinoProjects

Source

ArduinoProjects / ComponentExamples / MMA7361Accelerometer / MMA7361Accelerometer.ino

#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;

const float g_GravityMS2 = 9.80665f;

void setup()
{
 Serial.begin(9600);
 
 accelero.begin(31, 32, 30, 33, A0, A1, A2);
 //void begin(int sleepPin, int selfTestPin, int zeroGPin, int gSelectPin, int xPin, int yPin, int zPin);
 
 accelero.setARefVoltage(5); //sets the AREF voltage to 5V
 accelero.setSensitivity(LOW); //sets the sensitivity to +/-1.5G
 accelero.calibrate();
}

void loop()
{
 float x = g_GravityMS2*accelero.getXAccel()/100.0f;
 float y = g_GravityMS2*accelero.getYAccel()/100.0f;
 float z = g_GravityMS2*accelero.getZAccel()/100.0f;
 Serial.print("\nx: ");
 Serial.print(x);
 Serial.print(" \ty: ");
 Serial.print(y);
 Serial.print(" \tz: ");
 Serial.print(z);
 delay(250); //make it readable
}