The compass part

Dependencies:   CMPS03 mbed

Fork of mbed_cmp by Project group 3

Committer:
gegjackson
Date:
Tue Mar 01 15:21:35 2016 +0000
Revision:
1:5b42fa6e0a73
Parent:
0:2f8627e2b4c7
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gegjackson 0:2f8627e2b4c7 1 #include "CMPS03.h"
gegjackson 0:2f8627e2b4c7 2 #include "mbed.h"
gegjackson 1:5b42fa6e0a73 3
gegjackson 0:2f8627e2b4c7 4 CMPS03 compass(p9, p10, CMPS03_DEFAULT_I2C_ADDRESS);
gegjackson 0:2f8627e2b4c7 5 Serial pc(USBTX, USBRX);
gegjackson 1:5b42fa6e0a73 6 LocalFileSystem local("local"); // Create the local filesystem called "local"
gegjackson 1:5b42fa6e0a73 7 float data[100];
gegjackson 1:5b42fa6e0a73 8 DigitalOut myled(LED3);
gegjackson 1:5b42fa6e0a73 9
gegjackson 0:2f8627e2b4c7 10
gegjackson 0:2f8627e2b4c7 11 int main() {
gegjackson 0:2f8627e2b4c7 12
gegjackson 1:5b42fa6e0a73 13 for (int i=0; i<100; i++)
gegjackson 1:5b42fa6e0a73 14 {
gegjackson 1:5b42fa6e0a73 15 data[i] = (compass.readBearing() / 10.0);
gegjackson 1:5b42fa6e0a73 16 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
gegjackson 1:5b42fa6e0a73 17 }
gegjackson 0:2f8627e2b4c7 18
gegjackson 1:5b42fa6e0a73 19 myled = 1;//flash an led to display the program has stopped taking readings
gegjackson 1:5b42fa6e0a73 20 wait(0.2);
gegjackson 1:5b42fa6e0a73 21 myled = 0;
gegjackson 1:5b42fa6e0a73 22 wait(0.2);
gegjackson 1:5b42fa6e0a73 23
gegjackson 1:5b42fa6e0a73 24 FILE *fpcmp = fopen("/local/cmpvalues.txt", "w"); // Open "cmpvalues.txt"
gegjackson 1:5b42fa6e0a73 25 for (int i=0; i<100; i++)
gegjackson 1:5b42fa6e0a73 26 {
gegjackson 1:5b42fa6e0a73 27 fprintf(fpcmp,"%f \n ",data[i]); //print the data values to the file
gegjackson 0:2f8627e2b4c7 28 }
gegjackson 1:5b42fa6e0a73 29 fclose(fpcmp); //save and close the file
gegjackson 1:5b42fa6e0a73 30
gegjackson 1:5b42fa6e0a73 31 }