Implement a SD card into HW6

Dependencies:   SDFileSystem mbed

Fork of shomberg_hw_6 by Russell Shomberg

Revision:
18:699b41309be7
Parent:
12:ea407dcaff78
Child:
19:1f4dd59bbe6b
--- a/main.cpp	Wed Oct 31 22:08:29 2018 +0000
+++ b/main.cpp	Wed Oct 31 22:50:37 2018 +0000
@@ -3,61 +3,72 @@
     main.cpp
 
     Purpose:    Read signal from TMP36 connected to pin20
-                Display output voltage to terminal
-                Display difference in mV of output voltage to starting voltage on 2x 7-Segment Displays
-                    See outputs for pin configuration
-                Toggle switch connected to pin07 to convert displays to degC
-    
+                Toggle switch connected to pin07 activates SD logging
+                Log: Time Elasped, Current Voltage, Current Temp, Delta Temp
+                Finish log -> save file and send to USB serial port
+
     @author  Russell Shomberg
-    @created 2018-10-23
-    @revised 2018-10-25
+    @created 2018-10-31
+    @revised 2018-10-31
     @version 0.0
-    
-    Issues: No Decimal point for temperature    
-    
-*/ 
+
+    Issues:
+
+*/
 
 // INCLUDES
 #include "mbed.h"
-#include "SegDisplay.h"
 #include "OCE360Input.h"
+#include "SDFileSystem.h"
 
 // OUTPUTS
 Serial pc(USBTX, USBRX);        // for debugging
 
 // VARIABLES
 int outputT= 0;
-float v0;
-float deltav;
-float val;
+float starting_voltage;
+float starting_temp;
+
+float current_time;
+float current_voltage;
+float current_temp;
+
 
 
-int main() {
-    // read starting voltage from temperature sensor
-    v0 = read_sensor();
-    
+int main()
+{
+
     while(1) {
-        // Read Switch if on output temp else output mV
-        outputT = read_switch();
-        deltav = read_sensor()-v0;
-        
-        // Output to terminal
-        if (outputT) {
-            // Convert to temp
-            val = convert_mV_to_temp(deltav);
-            //printf("Temperature Difference = %1.2f degC\n\r", val);
+        while(read_switch()) {  // skip everything if switch is off
+            // Take initial readings
+            starting_voltage = read_sensor();
+            starting_temp = onvert_mV_to_temp(starting_voltage);
+
+            // Initialize a file
+
+            // Write header to file
+            //"Time (s), Voltage (mv), Temperature (C), Delta T (C)\n\r"
+
+            // start a loop that logging
+            // exiting this loop will initialize data save procedures
+            while(read_switch()) { // Main loop for logging
+
+                // Get data for logging
+                current_time = check_time();
+                current_voltage = read_sensor();
+                current_temp = convert_mV_to_temp(current_voltage);
+
+                //"%1.2f, %1.2f, %1.2f, %1.2f \n\r", current_time, current_voltage, current_temp, current_temp-starting_temp
+                
+                wait(1);
+            }
+            // This code runs when the switch is toggled off
+            // Close out file
+            
+            // Print to USB serial
+
         }
-
-        else {
-            val = deltav;
-            //printf("Voltage Difference = %1.2f mV\n\r", val);
-        }
-        
-        SegWrite(val);
-                
-        wait(1);
-        
+        // Re-enter main while loop
+        //continuously check for switch to turn on again
     }
-    
-}
-
+}
\ No newline at end of file