megan gimple / Mbed 2 deprecated gimple_A3_3_Temp_Light

Dependencies:   mbed

main.cpp

Committer:
mgimple
Date:
2021-10-27
Revision:
1:d706fb07041f
Parent:
0:61f876d07ef5
Child:
2:38d752717527

File content as of revision 1:d706fb07041f:

#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()
{
    while(1) {
        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;
            }
        }

    }
}