-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #3 #11
base: master
Are you sure you want to change the base?
fix #3 #11
Conversation
added AccelerometerTap code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove pointless blank lines.
resolved the requested changes.
do you wish for any other changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 tapThreshold
andint down
invoid 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 <[email protected]>
added AccelerometerTap code.