megan gimple / Mbed 2 deprecated gimple_A3_3_Temp_Light

Dependencies:   mbed

Revision:
3:0170897aa173
Parent:
2:38d752717527
diff -r 38d752717527 -r 0170897aa173 main.cpp
--- a/main.cpp	Wed Oct 27 17:48:12 2021 +0000
+++ b/main.cpp	Fri Oct 29 14:52:42 2021 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "math.h"
 
 Serial pc(USBTX,USBRX);
 DigitalOut Led1(LED1);
@@ -15,50 +16,38 @@
 float light_volt; //light voltage multiplied by 3.3 from mbed
 float light_res; //resistance through photocell
 float light_volt_raw; //raw voltage through photocell
-void temp_read();   //temperature reading function
-void light_read();  //light reading function
 
 
 int main()
 {
     while(1) {
-        temp_read();
-
-        light_read();
-    }
-}
+        volt_raw = therm.read(); //sets the raw data as a variable
+        volt = volt_raw*3.3; //converts raw voltage to the correct scale
+        float temp = (-1481.96)+ sqrt((2.1962*(powf(10,6)))+((1.8639-volt)/(3.88*(powf(10,-6))))); //converts voltage to temperature
+        pc.printf("Thermocell Voltage: %f V\r\n",volt);
+        pc.printf("Temperature: %f C\r\n",temp);
 
-void temp_read() //main temperature reading command to be called upon
-{
-    volt_raw = therm.read(); //sets the raw data as a variable
-    volt = volt_raw; //converts raw voltage to the correct scale for our mbed *3.3
-    temp = -1481.96+sqrt(((2.1962e6)+((1.8639-volt)/(3.88e-6)))); //converts voltage to temperature
-    pc.printf("TEMP %f Volts %3.1f Celsius \r\n",volt, temp);
-    wait(1);
+        if (temp>=15 && temp<20) {
+            Led1=1;
+        }
+        if (temp<15 && temp>=20) {
+            Led2=1;
+        }
+        if (temp>=25) {
+            Led3=1;
+        }
+
 
-    if (temp>=15) {
-        Led1=1;
-        if (temp>=20) {
-            Led2=1;
-            if (temp>=25) {
-                Led3=1;
-            }
+        light_volt_raw=light.read(); //sets the raw data as a variable
+        light_res=(10000/light_volt_raw)-10000;
+        light_volt=light_volt_raw*3.3;
+        pc.printf("Photocell Resistance: %f Ohms\r\n",light_res);
+        pc.printf("Photocell Voltage: %f \r\n",light_volt);
+        if (light_volt<1.55) { //the sensor is "completely blocked" by a finger at most values under 0.3 volts
+            Led4=1;
+        }
+        if (light_volt>1.55) {
+            Led4=0;
         }
     }
-}
-
-
-void light_read() //main light reading command to be called upon
-{
-    light_volt_raw=light.read(); //sets the raw data as a variable
-    light_res=(10000/light_volt_raw)-10000;     //converting voltage to resistance
-    light_volt=light_volt_raw*3.3;  //mbed outputs 3.3 volts
-    pc.printf("LIGHT %1.3f Voltz 6.2%f Ohms\r\n",light_volt,light_res);
-    wait(1);
-    if (light_volt<0.3) { //the sensor is "completely blocked" by a finger at most values under 0.3 volts. The whole photocell has to be covered however because even if a bit is showing it will read higher than 0.3
-        Led4=1;
-    }
-    if (light_volt>0.3) {
-        Led4=0;
-    }
-}
+}
\ No newline at end of file