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.
Fork of mbed_cmp by
Diff: main.cpp
- Revision:
- 1:5b42fa6e0a73
- Parent:
- 0:2f8627e2b4c7
--- 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