File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
examples/AccelerometerTap Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
3030float 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+
3234void 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 }
You can’t perform that action at this time.
0 commit comments