shared version

Dependencies:   ExtendedTimer ISL29125 SDFileSystem mbed

Link to the experiment wiki: http://www.whitworthnearspace.org/wiki/Dependence_of_photovoltaic_performance_on_light_spectrum

Revision:
2:cf208b7bb73e
Parent:
1:08f10b3443e4
--- a/final_main.cpp	Tue Apr 18 22:19:11 2017 +0000
+++ b/final_main.cpp	Thu Apr 27 16:45:22 2017 +0000
@@ -9,10 +9,15 @@
 //setting up sd card
 SDFileSystem sd(p5, p6, p7, p8, "drive");
 
+DigitalOut Alarm(p21);
+
 //UV Sensors are connected to p15 and p16
 AnalogIn UVSensor1(p15);
 AnalogIn UVSensor2(p16);
 
+//PV cells connected to p20
+AnalogIn PV(p20);
+
 //Temperature sensor; connected to p28 and p27 (with UVSensor2)
 I2C tempsensor(p28, p27);
 const int addr = 0x90;
@@ -25,7 +30,7 @@
 
 int main(){
     t.start();//starts the timer
-    
+    int alarmCount = 0;
     //Filesystem setting
     bool mountFailure = sd.mount();
     if (mountFailure !=0){
@@ -52,8 +57,8 @@
     uint16_t rgb1[3];
     uint16_t rgb2[3];
     
-    pc.printf("Time\tTemp\tUV1\tUV2\tR1\tG1\tB1\tR2\tG2\tB2\r\n");//printing out titles
-    fprintf(fp, "Time\tTemp\tUV1\tUV2\tR1\tG1\tB1\tR2\tG2\tB2\r\n");
+    pc.printf("Time\tTemp\tUV1\tUV2\tR1\tG1\tB1\tR2\tG2\tB2\tPV\r\n");//printing out titles
+    fprintf(fp, "Time\tTemp\tUV1\tUV2\tR1\tG1\tB1\tR2\tG2\tB2\tPV\r\n");
     while(1){
         if ((t.read_ms()%1000)==0){
             tempsensor.read(addr, temp_read, 2);
@@ -67,10 +72,22 @@
             fprintf(fp, "%.4f\t%.4f", UVSensor1.read(), UVSensor2.read());
             get_rgb1(rgb1);
             get_rgb2(rgb2);
-            pc.printf("\t%d\t%d\t%d\t%d\t%d\t%d\r\n", rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2]);
-            fprintf(fp, "\t%d\t%d\t%d\t%d\t%d\t%d\r\n", rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2]);
+            pc.printf("\t%d\t%d\t%d\t%d\t%d\t%d\t%.4f\r\n", rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2], PV.read());
+            fprintf(fp, "\t%d\t%d\t%d\t%d\t%d\t%d\t%.4f\r\n", rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2], PV.read());
             
-            if ((t.read_ms()%300000)==0){
+            if (alarmCount>36){
+                while(1)
+                {
+                    Alarm = 1;
+                    wait(0.1);
+                    Alarm = 0;
+                    wait(0.5);
+                }
+            }
+            
+            int tempTime = t.read_ms()%300000;
+            if (tempTime < 10000){
+                alarmCount++;
                 fclose(fp);
                 FILE* fp = fopen("/drive/data.txt", "a");
                 pc.printf("File reopen...\r\n");