fix #3#11
Conversation
added AccelerometerTap code.
per1234
left a comment
There was a problem hiding this comment.
You have forgotten to account for pseudo-acceleration caused by gravity. This causes whichever axis is pointing down to constantly register taps.
Please do a Tools > Auto Format if using the Arduino IDE or Ctrl + b if using Arduino Web Editor so that the formatting of your code will be consistent with Arduino's other examples.
|
|
||
| while (!Serial); | ||
|
|
||
| while (!IMU.begin()) { | ||
|
|
||
| Serial.println("Failed to initialize IMU!"); | ||
|
|
There was a problem hiding this comment.
| while (!Serial); | |
| while (!IMU.begin()) { | |
| Serial.println("Failed to initialize IMU!"); | |
| while (!Serial); | |
| while (!IMU.begin()) { | |
| Serial.println("Failed to initialize IMU!"); |
Remove pointless blank lines.
|
|
||
| } | ||
|
|
||
| float tapThreshold = 0.05 ; //0.05g acceleration in some direction is considered as tap. it can be change for the required sensitivity. |
There was a problem hiding this comment.
| float tapThreshold = 0.05 ; //0.05g acceleration in some direction is considered as tap. it can be change 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. |
|
|
||
| float tapThreshold = 0.05 ; //0.05g acceleration in some direction is considered as tap. it can be change for the required sensitivity. | ||
|
|
||
| int down = 3 ; // signifing the direction of which is facing downward 1 for x axis ; 2 for y axis ; 3 for z axis; |
There was a problem hiding this comment.
| int down = 3 ; // signifing the direction of which is facing downward 1 for x axis ; 2 for y axis ; 3 for z axis; | |
| int down = 3; // signifying the direction which is facing downward: 1 for x axis; 2 for y axis; 3 for z axis |
Fix formatting and typo.
Why not make this a char so you can do this:
char down = 'z'; // the axis which is facing downward|
|
||
| Serial.println("Tap detected across X-axis"); | ||
| } | ||
| if ((y > tapThreshold || y < -tapThreshold) && down != 2 ) { |
There was a problem hiding this comment.
| if ((y > tapThreshold || y < -tapThreshold) && down != 2 ) { | |
| if ((y > tapThreshold || y < -tapThreshold) && down != 2) { |
Fix formatting.
|
|
||
| Serial.println("Tap detected across Y-axis"); | ||
| } | ||
| if ((z > tapThreshold || z < -tapThreshold)&& down != 3 ) { |
There was a problem hiding this comment.
| if ((z > tapThreshold || z < -tapThreshold)&& down != 3 ) { | |
| if ((z > tapThreshold || z < -tapThreshold) && down != 3) { |
Fix formatting.
| Arduino LSM6DS3 - Accelerometer Tap | ||
|
|
||
| this code is to detect tap | ||
|
|
There was a problem hiding this comment.
Remove pointless blank lines.
resolved the requested changes.
|
do you wish for any other changes? |
MisterAwesome23
left a comment
There was a problem hiding this comment.
Hey @tkhabia
Thanks for the pull request :)
I have a few queries with the suggested code-
-
How can we detect a tap along all directions? Setting down to a value of 3 (hard-coded) and with this logic, we will not be able to leverage of one of the directions Z axes in this case.
-
I agree with @per1234 of using char for X,Y,Z for direction rather than 1,2,3 since it is more intuitive.
-
Consider adding
float tapThresholdandint downinvoid setup(){}since they're a part of initialization and makes more relevance there.
More on this- https://forum.arduino.cc/index.php?topic=203395.0 -
If LSM6DS3 provides with positive and negative axes (Not sure on this, CurieIMU does, maybe this will help- https://www.st.com/resource/en/datasheet/lsm6ds3.pdf) direction as well consider adding that as well since it'll be more accurate
tried to resolve the requested querry.
|
|
Co-authored-by: per1234 <accounts@perglass.com>
added AccelerometerTap code.