s
Dependencies: C12832_lcd CMPS03 GPS MMA7660 mbed
Diff: main.cpp
- Revision:
- 0:ed3bb00f66af
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 08 14:50:55 2016 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "CMPS03.h"//added +#include "MMA7660.h" +#include "stdio.h" //needed? +#include "GPS.h" + + +/*THIS FILE IS MADE TO RUN ON THE MBED. IT WILL TAKE ACCELEROMETER VALUES AND WRITE THEM +TO A TEXT FILE AND THEN A CONNECTED COMPUTER*/ +GPS gps(p13, p14);// which pins??? +CMPS03 compass(p9, p10, CMPS03_DEFAULT_I2C_ADDRESS);//added +DigitalOut myled(LED1); +MMA7660 MMA(p28, p27); // Accelerometer connections +float ax, ay, az; //allocations for the x, y, z values +Serial pc(USBTX,USBRX); // serial port +LocalFileSystem local("local"); // Create the local filesystem called "local" +int main() +{ + float data[100]; // three data arrays, with 100 entries + float data1[100]; + float data2[100]; + float data3[100]; + + + for (int i=0; i<100; i++) + { + ax=MMA.x(); //ax is the x value from the accelerometer. the *90 part is to get an angle + data[i] = ax ; //place the value of the accelerometer into the 1st array + ay=MMA.y(); + data1[i] = ay ; + az=MMA.z(); + data2[i] = az; + data3[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 + } + + FILE *fp = fopen("/local/values.txt", "w"); // Open "values.txt" + fprintf(fp,"Location is: %f , %f", gps.longitude, gps.latitude); + for (int i=0; i<100; i++) + { + fprintf(fp,"%i %f %f %f Bearing:%f \r\n ", i, data[i], data1[i], data2[i], data3[i]); //print all the data values to the file + } + fclose(fp); //save and close the file + + + + + +} + + +