Project group 3
/
mbed_project1
the accelerometer part
Diff: main.cpp
- Revision:
- 0:473315f27686
- Child:
- 1:e68be371bf77
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 29 15:08:03 2016 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" +#include "MMA7660.h" +#include "stdio.h" +/*THIS FILE IS MADE TO RUN ON THE MBED. IT WILL TAKE ACCELEROMETER VALUES AND WRITE THEM +TO A TEXT FILE AND THE CONNECTED COMPUTER*/ + +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]; + + + for (int i=0; i<100; i++) + { + ax=MMA.x(); //ax is the x value from the accelerometer + 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; + } + + myled = 1;//flash an led to display the program has stopped taking readings + wait(0.2); + myled = 0; + wait(0.2); + + FILE *fp = fopen("/local/accvalues.txt", "w"); // Open "accvalues.txt" + for (int i=0; i<100; i++) + { + fprintf(fp,"%f %f %f\n",data[i], data1[i], data2[i]); //print the data values to the file + } + fclose(fp); //save and close the file + + pc.printf("these are the accelerometer values: \n"); + for (int i=0; i<100; i++) + { + pc.printf("%f %f %f\n",data[i], data1[i], data2[i]); //print the values to the pc via putty + } +} + + +