22 Arduino LSM6DS3 - Accelerometer Tap
33
44 this code is to detect tap
5-
65 using IMU.accelerationAvailable()
76
87*/
@@ -15,39 +14,29 @@ void setup() {
1514 while (!Serial);
1615
1716 while (!IMU.begin ()) {
18-
1917 Serial.println (" Failed to initialize IMU!" );
20-
21- delay (3000 ); // wait for 3 sec and check if it can be initialize again
22-
18+ delay (3000 ); // wait for 3 sec and check if it can be initialized again
2319 }
24-
2520}
21+ float tapThreshold = 0.05 ; // 0.05 g acceleration in some direction is considered as tap. it can be change for the required sensitivity.
2622
27- float tapThreshold = 0.05 ; // 0.05g acceleration in some direction is considered as tap. it can be change for the required sensitivity.
28-
29- int down = 3 ; // signifing the direction of which is facing downward 1 for x axis ; 2 for y axis ; 3 for z axis;
23+ int down = 3 ; // signifying the direction of which is facing downward 1 for x axis ; 2 for y axis ; 3 for z axis;
3024
3125void loop () {
32-
3326 float x, y, z;
34-
3527 if (IMU.accelerationAvailable ()) {
36-
3728 IMU.readAcceleration (x, y, z);
38-
39- if ((x > tapThreshold || x < -tapThreshold) && down != 1 ) {
40-
29+
30+ if ((x > tapThreshold || x < -tapThreshold) && down != 1 ) {
4131 Serial.println (" Tap detected across X-axis" );
4232 }
43- if ((y > tapThreshold || y < -tapThreshold) && down != 2 ) {
44-
33+
34+ if ((y > tapThreshold || y < -tapThreshold) && down != 2 ) {
4535 Serial.println (" Tap detected across Y-axis" );
4636 }
47- if ((z > tapThreshold || z < -tapThreshold)&& down != 3 ) {
48-
37+
38+ if ((z > tapThreshold || z < -tapThreshold)&& down != 3 ) {
4939 Serial.println (" Tap detected across Z-axis" );
5040 }
5141 }
52-
5342}
0 commit comments