Created
March 8, 2019 10:23
-
-
Save li2hub/ef71c9e13d9f09e901049833bb5a017e 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> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_ADXL345_U.h> | |
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345); | |
float val_x=0,val_y=0,val_z=0; | |
float sig_x=0,sig_y=0,sig_z=0; | |
float alpha=0.1; | |
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); | |
val_x=(event.acceleration.x)/9.8; | |
val_y=(event.acceleration.y)/9.8; | |
val_z=(event.acceleration.z)/9.8; | |
sig_x=(alpha*val_x)+((1.0-alpha)*sig_x); | |
sig_y=(alpha*val_y)+((1.0-alpha)*sig_y); | |
sig_z=(alpha*val_z)+((1.0-alpha)*sig_z); | |
//Serial.print(sig_x); Serial.print(","); | |
Serial.print(val_z); Serial.print(","); | |
Serial.println(sig_z); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment