the accelerometer part

Dependencies:   MMA7660 mbed

Files at this revision

API Documentation at this revision

Comitter:
gegjackson
Date:
Tue Mar 01 15:07:04 2016 +0000
Parent:
0:473315f27686
Commit message:
b

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Feb 29 15:08:03 2016 +0000
+++ b/main.cpp	Tue Mar 01 15:07:04 2016 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
 #include "MMA7660.h"
-#include "stdio.h"
+#include "stdio.h" //needed?
 /*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*/
+TO A TEXT FILE AND THEN A CONNECTED COMPUTER*/
 
 DigitalOut myled(LED1);
 MMA7660 MMA(p28, p27); // Accelerometer connections
@@ -18,12 +18,14 @@
 
     for (int i=0; i<100; i++) 
     {
-        ax=MMA.x(); //ax is the x value from the accelerometer
+        ax=90*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();
+        ay=90*MMA.y();
         data1[i] = ay ;
-        az=MMA.z();
+        az=90*MMA.z();
         data2[i] = az;
+        
+        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
@@ -31,14 +33,14 @@
     myled = 0;
     wait(0.2);
 
-    FILE *fp = fopen("/local/accvalues.txt", "w"); // Open "accvalues.txt"
+    FILE *fpacc = 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
+        fprintf(fpacc,"%f %f %f \n ",data[i], data1[i], data2[i]); //print the data values to the file
     }
-    fclose(fp); //save and close the file
+    fclose(fpacc); //save and close the file
 
-    pc.printf("these are the accelerometer values: \n");
+    pc.printf("these are the accelerometer values: \n");//we will not need this on the day of testing, we only need to save the data on the mbed
     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