megan gimple / Mbed 2 deprecated gimple_A3_3_Temp_Light

Dependencies:   mbed

Revision:
0:61f876d07ef5
Child:
1:d706fb07041f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 27 16:31:41 2021 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX);
+DigitalOut Led1(LED1);
+DigitalOut Led2(LED2);
+DigitalOut Led3(LED3);
+DigitalOut Led4(LED4);
+AnalogIn therm(p19);
+AnalogIn light(p20);
+
+
+float volt_raw; //raw data read from thermistor
+float volt; //final voltage after conversion
+float temp; //converted temperature in degrees celsius
+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
+void templight();   //lgith and temp reading function
+
+int main()
+{
+
+    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*3.3; //converts raw voltage to the correct scale for our mbed
+        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<50) {
+
+            if (temp>=20) {
+                Led1=1;
+                if (temp>=25) {
+                    Led2=1;
+                    if (temp>=30) {
+                        Led3=1;
+                    }
+                }
+            }
+        }
+    }
+
+    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