Here is a little code snippet to spit the values of the MMA8453 Accelerometer out on the Serial port. Make sure to include the I2C library and the MMA8453 library in the sketch. You can download them both lower down on this page!
#include "I2C.h"#include "MMA8453Q.h"MMA8453Q accelerometer;
Now get accelerometer readings with the functions getX(), getY(), and getZ(), as in:
int x = accelerometer.getX();
The values can be positive or negative and range from -512 to 512. See the entire example sketch below.
#include #include MMA8453Q accelerometer;void setup(){ Serial.begin(9600);} void loop(){ Serial.print("X:"); Serial.print(accelerometer.getX()); Serial.print(", Y:"); Serial.print(accelerometer.getY()); Serial.print(", Z:"); Serial.print(accelerometer.getZ()); Serial.println(); delay(300);}