-
Notifications
You must be signed in to change notification settings - Fork 32
fix #3 #11
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
base: master
Are you sure you want to change the base?
fix #3 #11
Changes from 6 commits
44d169b
c3502b7
71d1a8d
481761e
8e40c31
5db757f
cfc45a8
1618d6b
46b3e86
195dcbc
3eb3475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||||||||||||||||||
/* | ||||||||||||||||||||||
Arduino LSM6DS3 - Accelerometer Tap | ||||||||||||||||||||||
|
||||||||||||||||||||||
this code is to detect tap | ||||||||||||||||||||||
|
||||||||||||||||||||||
using IMU.accelerationAvailable() | ||||||||||||||||||||||
|
||||||||||||||||||||||
aentinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
*/ | ||||||||||||||||||||||
|
||||||||||||||||||||||
#include <Arduino_LSM6DS3.h> | ||||||||||||||||||||||
|
||||||||||||||||||||||
void setup() { | ||||||||||||||||||||||
Serial.begin(9600); | ||||||||||||||||||||||
|
||||||||||||||||||||||
while (!Serial); | ||||||||||||||||||||||
|
||||||||||||||||||||||
while (!IMU.begin()) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
Serial.println("Failed to initialize IMU!"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove pointless blank lines. |
||||||||||||||||||||||
delay (3000); // wait for 3 sec and check if it can be initialize again | ||||||||||||||||||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Fix formatting and typo. Why not make this a char down = 'z'; // the axis which is facing downward |
||||||||||||||||||||||
|
||||||||||||||||||||||
void loop() { | ||||||||||||||||||||||
|
||||||||||||||||||||||
float x, y, z; | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (IMU.accelerationAvailable()) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
IMU.readAcceleration(x, y, z); | ||||||||||||||||||||||
|
||||||||||||||||||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
if ((x > tapThreshold || x < -tapThreshold) && down != 1 ) { | ||||||||||||||||||||||
tkhabia marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove pointless blank lines. |
||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Fix formatting. |
||||||||||||||||||||||
|
||||||||||||||||||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Fix formatting. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Serial.println("Tap detected across Z-axis"); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
} |
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.