Project group 3
/
mbed_cmp
The compass part
Fork of mbed_cmp by
Revision 1:5b42fa6e0a73, committed 2016-03-01
- Comitter:
- gegjackson
- Date:
- Tue Mar 01 15:21:35 2016 +0000
- Parent:
- 0:2f8627e2b4c7
- Commit message:
- a
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2f8627e2b4c7 -r 5b42fa6e0a73 main.cpp --- a/main.cpp Mon Feb 29 15:11:21 2016 +0000 +++ b/main.cpp Tue Mar 01 15:21:35 2016 +0000 @@ -1,18 +1,31 @@ #include "CMPS03.h" #include "mbed.h" + CMPS03 compass(p9, p10, CMPS03_DEFAULT_I2C_ADDRESS); Serial pc(USBTX, USBRX); +LocalFileSystem local("local"); // Create the local filesystem called "local" +float data[100]; +DigitalOut myled(LED3); + int main() { - pc.printf("Starting CMPS03 test...\n"); - - while(1){ - - wait(0.1); - - pc.printf("Bearing is: %f\n", compass.readBearing() / 10.0); + for (int i=0; i<100; i++) + { + data[i] = (compass.readBearing() / 10.0); + wait (0.1);// so all the results aren't taken as quickly as the mbed can process. total time = wait time * number of items in array + } + myled = 1;//flash an led to display the program has stopped taking readings + wait(0.2); + myled = 0; + wait(0.2); + + FILE *fpcmp = fopen("/local/cmpvalues.txt", "w"); // Open "cmpvalues.txt" + for (int i=0; i<100; i++) + { + fprintf(fpcmp,"%f \n ",data[i]); //print the data values to the file } - -} \ No newline at end of file + fclose(fpcmp); //save and close the file + + } \ No newline at end of file