Skip to content

Commit 71d1a8d

Browse files
committed
Applied the requested changes in the example file.
1 parent c3502b7 commit 71d1a8d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"compilerPath": "/usr/bin/gcc",
10+
"cStandard": "c11",
11+
"cppStandard": "c++17",
12+
"intelliSenseMode": "clang-x64"
13+
}
14+
],
15+
"version": 4
16+
}

examples/AccelerometerTap/AccelerometerTap.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
this code is to detect tap
55
6-
usign IMU.accelerationAvailable()
6+
using IMU.accelerationAvailable()
77
88
Made by
99
tanmay khabia
@@ -29,6 +29,8 @@ void setup() {
2929

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

32+
int down = 3 ; // signifing the direction of which is facing downward 1 for x axis ; 2 for y axis ; 3 for z axis;
33+
3234
void loop() {
3335

3436
float x, y, z;
@@ -37,15 +39,15 @@ void loop() {
3739

3840
IMU.readAcceleration(x, y, z);
3941

40-
if (x > tapThreshold || x < -tapThreshold) {
42+
if ((x > tapThreshold || x < -tapThreshold) && down != 1 ) {
4143

4244
Serial.println("Tap detected across X-axis");
4345
}
44-
if (y > tapThreshold || y < -tapThreshold) {
46+
if ((y > tapThreshold || y < -tapThreshold) && down != 2 ) {
4547

4648
Serial.println("Tap detected across Y-axis");
4749
}
48-
if (z > tapThreshold || z < -tapThreshold) {
50+
if ((z > tapThreshold || z < -tapThreshold)&& down != 3 ) {
4951

5052
Serial.println("Tap detected across Z-axis");
5153
}

0 commit comments

Comments
 (0)