Skip to content

Instantly share code, notes, and snippets.

@li2hub
Last active February 18, 2019 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li2hub/d6dbc866fc82975a6d2707e93451c942 to your computer and use it in GitHub Desktop.
Save li2hub/d6dbc866fc82975a6d2707e93451c942 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
void setup()
{
Serial.begin(115200);
if(!accel.begin())
{
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
accel.setRange(ADXL345_RANGE_4_G);
}
void loop()
{
sensors_event_t event;
accel.getEvent(&event);
Serial.print((event.acceleration.x)/9.8); Serial.print(",");
Serial.print((event.acceleration.y)/9.8); Serial.print(",");
Serial.println((event.acceleration.z)/9.8);
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment