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: USBDevice mbed DipCortex-USB-EEProm
Diff: main.cpp
- Revision:
- 8:9a3d2d28e7e5
- Parent:
- 7:930020a7dc9e
- Child:
- 9:f37125673b91
--- a/main.cpp Thu Sep 03 16:03:07 2015 +0000 +++ b/main.cpp Thu Sep 03 17:13:29 2015 +0000 @@ -20,6 +20,13 @@ int Y_accelleration=0; int X_accelleration=0; +// Storage arrays for X,Y,Z +uint16_t Z_store[MAXSAMPLES]={}; +uint16_t Y_store[MAXSAMPLES]={}; +uint16_t X_store[MAXSAMPLES]={}; +int Sample_index=0; +int Last_sample=0; + // Control variables bool monitoring=FALSE; // Controls whether monitoring is running or stopped @@ -73,19 +80,33 @@ void monitor_accelleration(void) { X_accelleration=X_in.read_u16(); // Read and print X accelleration + X_store[Sample_index]=X_accelleration; X_accelleration=(X_accelleration-(0xFFFF/2)); // Convert to change in accelleration X_accelleration=X_accelleration/16; pc.printf("X: %d ",X_accelleration); Y_accelleration=Y_in.read_u16(); // Read and print Y accelleration + Y_store[Sample_index]=Y_accelleration; Y_accelleration=(Y_accelleration-(0xFFFF/2)); // Convert to change in accelleration Y_accelleration=Y_accelleration/16; pc.printf("Y: %d ",Y_accelleration); Z_accelleration=Z_in.read_u16(); // Read and print Z accelleration + Z_store[Sample_index]=Z_accelleration; Z_accelleration=(Z_accelleration-(0xFFFF/2)); // Convert to change in accelleration Z_accelleration=Z_accelleration/16; pc.printf("Z: %d \r\n",Z_accelleration); + + pc.printf("Sample index: %d \r\n",Sample_index); + Sample_index++; + + if (Sample_index>=MAXSAMPLES) + { + pc.printf("Stopping - full!\r\n"); + monitoring=FALSE; + monitor_tick.detach(); + Last_sample=Sample_index; + } } // ------------------------------------------------------------------------------------------------------------ @@ -93,6 +114,7 @@ // ------------------------------------------------------------------------------------------------------------ int main( void ) { +int i; // Initalise the LPC1347 init(); @@ -104,7 +126,7 @@ pc.printf("+-------------------------------------------+\r\n"); pc.printf("| 3-axis accelleration measurer |\r\n"); pc.printf("| Laurence Halfpenny |\r\n"); - pc.printf("| Version 1.0 |\r\n"); + pc.printf("| Version 1.2 |\r\n"); pc.printf("+-------------------------------------------+\r\n"); @@ -112,15 +134,17 @@ while (TRUE) { pc.printf("+-------------------------------------------+\r\n"); - pc.printf("| V 1.0 MENU: |\r\n"); + pc.printf("| V 1.2 MENU: |\r\n"); pc.printf("| 1: Start monitoring |\r\n"); pc.printf("| 2: Stop monitoring |\r\n"); + pc.printf("| 3: Stop / Dump values |\r\n"); pc.printf("+-------------------------------------------+\r\n"); switch(WaitForSerialCommand()) { case '1': pc.printf("Starting monitor\r\n"); + Sample_index=0; monitoring=TRUE; monitor_tick.attach(&monitor_accelleration,MONITORINTERVAL); break; @@ -129,6 +153,28 @@ pc.printf("Stopping monitoring\r\n"); monitoring=FALSE; monitor_tick.detach(); + Last_sample=Sample_index; + break; + + case '3': + if (monitoring==TRUE) + { + pc.printf("Stopping monitoring\r\n"); + monitoring=FALSE; + monitor_tick.detach(); + Last_sample=Sample_index; + } + + if (Last_sample>0) + { + for (i=0; i<Last_sample; i++) + { + pc.printf("No.: %d ",i); + pc.printf("X: %d ",X_store[i]); + pc.printf("Y: %d ",Y_store[i]); + pc.printf("Z: %d \r\n",Z_store[i]); + } + } break; default: