Lauren Taylor / Mbed 2 deprecated phototransistor

Dependencies:   mbed

Revision:
5:603c549bfefa
Parent:
4:327441ad8cf6
Child:
6:892ecb5fcfb9
--- a/main.cpp	Sat Mar 10 18:50:31 2018 +0000
+++ b/main.cpp	Thu Apr 05 15:42:25 2018 +0000
@@ -6,23 +6,28 @@
 DigitalOut ledBlue(p26);
 DigitalOut ledError(LED3);
 
+//This is our timer
 Ticker countClock;
- 
+
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
 
 Serial pc(USBTX,USBRX); 
 
 float checkLightSensor(int n);
 
+//Switches the on states of the LEDs in the sphere
 void ledSwitch();
 
+//This should save the data to the sd card *This isn't working right now*
 void save();
 
- FILE *fp;
+FILE *fp = NULL;
  
 int main() { 
-    mkdir("/sd/mydir", 0777);
-    fp = fopen("/sd/mydir/sdtest.txt", "w");
+    fp = fopen("/sd/mydir/sdtest.txt", "a");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
     int checkTimes = 10; 
     ledRed = true;
     ledBlue = false;
@@ -33,11 +38,15 @@
         ledError = true;
     }
     countClock.attach(&save, 10);
+    fprintf(fp,"\n\r\n\r\n\rBlue Light, Red Light\n\r\n\r\n\r");
     while(true) {
+        //Blue Light
         ledSwitch();
         pc.printf("%.4f, ", checkLightSensor(checkTimes));
         fprintf(fp,"%.4f, ", checkLightSensor(checkTimes));
         wait(0.2);
+        
+        //Red Light
         ledSwitch();
         pc.printf("%.4f\r\n", checkLightSensor(checkTimes));
         fprintf(fp,"%.4f\r\n", checkLightSensor(checkTimes));
@@ -63,12 +72,11 @@
 void save(){
     ledError = true;
     fclose(fp);
-    fp = fopen("/sd/mydir/sdtest.txt", "w+");
+    fp = fopen("/sd/mydir/sdtest.txt", "a");
     if(fp == NULL) {
         error("Could not open file for write\n");
         ledError = true;
     }
-    fprintf(fp,"Saved\n\r");
-    pc.printf("Saved\n\r");
+    pc.printf("\n\rSaved\n\r");
     ledError = false;
 }
\ No newline at end of file