Final Commit

Dependencies:   mbed

Revision:
0:d08b5dcb3f52
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 04 21:30:23 2019 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+DigitalOut led1(p24);
+DigitalOut led2(p23);
+DigitalOut led3(p22);
+DigitalOut led4(p21);
+AnalogIn photo(p15);
+AnalogIn LM19(p18);
+Serial pc(USBTX, USBRX);
+
+struct NMEA{
+    char header[5];
+    char buffer[100];
+    char checksum[2];
+};
+
+NMEA data;
+Timer t;
+    
+int main() {
+    t.start(); 
+    while(1) {
+        float light = photo.read();
+        float temp = LM19.read();
+        float tempC = (1.8663 - 3.3*temp)/0.01169;
+        //print NMEA string
+         pc.printf("$TTMPL  %f, %f, %f, %f; \r\n", t.read(), temp, tempC, light);
+        if (tempC < 20 & light > 1.75) {
+        led1 = 1;
+        led2 = 0;
+        led3 = 0;
+        led4 = 0;
+        // 3.3 print out 
+        pc.printf("$TTMPL  %f, %f, %f, Cold, %f, Day; \r\n", t.read(), temp, tempC, light);
+        } 
+        if (tempC < 20 & light < 1.75) {
+        led1 = 0;
+        led2 = 1;
+        led3 = 0;
+        led4 = 0;
+         // 3.3 print out 
+        pc.printf("$TTMPL  %f, %f, %f, Cold, %f, Night; \r\n", t.read(), temp, tempC, light);
+        }
+        if (tempC > 20 & light > 1.75) {
+        led1 = 0;
+        led2 = 0;
+        led3 = 1;
+        led4 = 0;
+         // 3.3 print out 
+         pc.printf("$TTMPL  %f, %f, %f, Hot, %f, Day; \r\n", t.read(), temp, tempC, light);
+        }
+        if (tempC > 20 & light < 1.75) {
+        led1 = 0;
+        led2 = 0;
+        led3 = 0;
+        led4 = 1;
+         // 3.3 print out 
+         pc.printf("$TTMPL  %f, %f, %f, Hot, %f, Night; \r\n", t.read(), temp, tempC, light);
+        }
+        wait(5);
+            
+            //clean serial ports 
+            while(pc.readable()){
+            pc.getc();
+            
+            }
+        }
+        }
+    
+    
+