Created
March 22, 2018 16:54
-
-
Save nseidle/658996fdf13cd52efd7f3bc941643954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> // Must include Wire library for I2C | |
#include <SparkFun_MMA8452Q.h> | |
MMA8452Q accel(0x1D); // Initialize the MMA8452Q with an I2C address of 0x1C (SA0=0) | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println("MMA8452Q Test Code!"); | |
accel.init(SCALE_8G, ODR_800); | |
//Wire.setClock(400000); //Fast I2C | |
} | |
long lastPrint = millis(); | |
void loop() | |
{ | |
if (accel.available()) | |
{ | |
accel.read(); | |
printCalculatedAccels(); | |
Serial.print(" Hz: "); | |
Serial.print(1000 / (millis() - lastPrint)); | |
Serial.println(); // Print new line every time. | |
lastPrint = millis(); | |
} | |
} | |
void printCalculatedAccels() | |
{ | |
Serial.print(accel.cx, 3); | |
Serial.print("\t"); | |
Serial.print(accel.cy, 3); | |
Serial.print("\t"); | |
Serial.print(accel.cz, 3); | |
Serial.print("\t"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment