Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL362 mbed MPL3115A2
Revision 12:c6b056ad171e, committed 2018-02-22
- Comitter:
- htdoughe
- Date:
- Thu Feb 22 21:29:19 2018 +0000
- Parent:
- 10:8dcc46dd53bf
- Child:
- 13:1cae1960370c
- Commit message:
- documentation written for virbration detection
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| report.txt | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 22 21:13:54 2018 +0000
+++ b/main.cpp Thu Feb 22 21:29:19 2018 +0000
@@ -2,7 +2,7 @@
#include "ADXL362.h"
#include "string.h"
-DigitalOut led1(LD3);
+DigitalOut led1(LED3);
//map of register values and names
int regids[34];
@@ -133,7 +133,7 @@
adxl362.reset();
wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
adxl362.set_mode(ADXL362::MEASUREMENT);
- int8_t x,y,z, initx, inity, intiz;
+ int8_t x,y,z, initx, inity, initz;
int start, length;
start = 0;
length = 5;
@@ -151,9 +151,9 @@
x=adxl362.scanx_u8();
y=adxl362.scany_u8();
z=adxl362.scanz_u8();
- if(x > initx+2 || y > inity+2 || z > initz+2){
+ if(x > initx+2 || y > inity+2 || z > initz+2 || x > initx-2 || y > inity-2 || z > initz-2){
led1 = 1;
- wait_ms(200);
+ wait_ms(2000);
led1 = 0;
}
printf("x = %d y = %d z = %d\r\n",x,y,z);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/report.txt Thu Feb 22 21:29:19 2018 +0000 @@ -0,0 +1,16 @@ +# Documentation for Vibration Detection + +Our algorithm is fairly simple right now; it measures knocks by comparing x, y, and z +values to an initial baseline set of values. When the program starts, it saves +initx, inity, and initz (uint8_t values); these are the initial baseline values for +each axis of measurement for the accelerometer. The program then enters a +perpetual while loop that measures x, y, and z and compares those new measurements +to their respective initial values. If any of these measured values vary from their +initial values by more than 2 (in either a positive or negative direction), the +LED lights for 2 seconds and measurement pauses. After those 2 seconds, measurement +resumes. + +This algorithm assumes 2 main things about the evironment: that any knock is +significant enough to change the measured value from the initial value by at least 3, +and that the baseline does not change (that is, that the board's orientation is fixed +during program execution). \ No newline at end of file