forked from arduino-libraries/Arduino_LSM6DS3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added AccelerometerTap code.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Arduino LSM6DS3 - Accelerometer Tap | ||
this is a code to detect tap | ||
via the help of acceleration Available | ||
and the direction it is in and print it on | ||
the serial monitor. | ||
Made by | ||
tanmay khabia | ||
*/ | ||
|
||
#include <Arduino_LSM6DS3.h> | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial); | ||
|
||
while (!IMU.begin()) { | ||
Serial.println("Failed to initialize IMU!"); | ||
|
||
delay (3000); // wait for 3 sec and check if it can be initialize again | ||
} | ||
} | ||
float tapThreshold = 0.05 ; //0.49 m/sec^2 acceleration in some direction is considered as tap. it can be change for the required sensitivity. | ||
void loop() { | ||
float x, y, z; | ||
if (IMU.accelerationAvailable()) { | ||
IMU.readAcceleration(x, y, z); | ||
if(x > tapThreshold | x < -tapThreshold) | ||
Serial.println("Tap detected across X-axis"); | ||
if(y > tapThreshold | y < -tapThreshold) | ||
Serial.println("Tap detected across Y-axis"); | ||
if(z > tapThreshold | z < -tapThreshold) | ||
Serial.println("Tap detected across Z-axis"); | ||
} | ||
} |