Skip to content

fix #3 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
38 changes: 38 additions & 0 deletions examples/AccelerometerTap/AccelerometerTap.ino
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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Remove pointless blank lines.

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");
}
}