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
Diff: main.cpp
- Revision:
- 18:216cc41b55f3
- Parent:
- 17:6a08357dbb3f
- Child:
- 19:51b2b42a82f1
--- a/main.cpp Fri Feb 23 16:52:30 2018 +0000 +++ b/main.cpp Fri Feb 23 16:56:18 2018 +0000 @@ -3,7 +3,7 @@ #include "string.h" #include "MPL3115A2.h" -DigitalOut led1(LED3); +DigitalOut led3(LED3); //map of register values and names for the adxl int regids[34]; @@ -138,6 +138,7 @@ inity=adxl362.scany_u8(); initz=adxl362.scanz_u8(); int count = 0; + int bs = 7; while(1) { //get the values of x, y, and z to test for a knock @@ -145,12 +146,12 @@ y=adxl362.scany_u8(); z=adxl362.scanz_u8(); //if x, y, or z vary from baseline by at least 3, a knock has occured. - if(x > initx+2 || y > inity+2 || z > initz+2 || x > initx-2 || y > inity-2 || z > initz-2){ - led1 = 1; + if(x > initx+bs || y > inity+bs || z > initz+bs || x > initx-bs || y > inity-bs || z > initz-bs){ + led3 = 1; count++; printf("number of knocks: %d\r\n", count); wait_ms(2000); - led1 = 0; + led3 = 0; } //printf("x = %d y = %d z = %d\r\n",x,y,z); wait_ms(100);