Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tried to resolve the requested querry.
  • Loading branch information
tkhabia committed Apr 1, 2020
1 parent 1618d6b commit 46b3e86
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions examples/AccelerometerTap/AccelerometerTap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,42 @@

#include <Arduino_LSM6DS3.h>

float tapThreshold ;
float xi, yi , zi ;

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 initialized again
}

if (IMU.accelerationAvailable()) {
IMU.readAcceleration(xi, yi, zi); // initial values of acceleration including gravity or some zero error.
}

tapThreshold = 0.05; //0.05 g acceleration in some direction is considered as tap. it can be changed for the required sensitivity.
}
float tapThreshold = 0.05; //0.05 g acceleration in some direction is considered as tap. it can be changed for the required sensitivity.

int down = 3; // signifying the direction of which is facing downward 1 for x axis; 2 for y axis; 3 for z axis;

void loop() {
float x, y, z;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);

if ((x > tapThreshold || x < -tapThreshold) && down != 1) {

// workes on difference from initial acceleration to the current acceleration
if (x -xi > tapThreshold || x-xi < -tapThreshold){
Serial.println("Tap detected across X-axis");
}

if ((y > tapThreshold || y < -tapThreshold) && down != 2) {
if (y-yi > tapThreshold || y-yi < -tapThreshold){
Serial.println("Tap detected across Y-axis");
}

if ((z > tapThreshold || z < -tapThreshold) && down != 3) {
if (z-zi > tapThreshold || z-zi < -tapThreshold) {
Serial.println("Tap detected across Z-axis");
}
}
Expand Down

0 comments on commit 46b3e86

Please sign in to comment.