megan gimple / Mbed 2 deprecated gimple_A3_3_Temp_Light

Dependencies:   mbed

Committer:
mgimple
Date:
Wed Oct 27 17:34:19 2021 +0000
Revision:
1:d706fb07041f
Parent:
0:61f876d07ef5
Child:
2:38d752717527
led 1 on always; led4 blinks but not in repsnse to covering the photo cell

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mgimple 0:61f876d07ef5 1 #include "mbed.h"
mgimple 0:61f876d07ef5 2
mgimple 0:61f876d07ef5 3 Serial pc(USBTX,USBRX);
mgimple 0:61f876d07ef5 4 DigitalOut Led1(LED1);
mgimple 0:61f876d07ef5 5 DigitalOut Led2(LED2);
mgimple 0:61f876d07ef5 6 DigitalOut Led3(LED3);
mgimple 0:61f876d07ef5 7 DigitalOut Led4(LED4);
mgimple 0:61f876d07ef5 8 AnalogIn therm(p19);
mgimple 0:61f876d07ef5 9 AnalogIn light(p20);
mgimple 0:61f876d07ef5 10
mgimple 0:61f876d07ef5 11
mgimple 0:61f876d07ef5 12 float volt_raw; //raw data read from thermistor
mgimple 0:61f876d07ef5 13 float volt; //final voltage after conversion
mgimple 0:61f876d07ef5 14 float temp; //converted temperature in degrees celsius
mgimple 0:61f876d07ef5 15 float light_volt; //light voltage multiplied by 3.3 from mbed
mgimple 0:61f876d07ef5 16 float light_res; //resistance through photocell
mgimple 0:61f876d07ef5 17 float light_volt_raw; //raw voltage through photocell
mgimple 0:61f876d07ef5 18 void temp_read(); //temperature reading function
mgimple 0:61f876d07ef5 19 void light_read(); //light reading function
mgimple 0:61f876d07ef5 20 void templight(); //lgith and temp reading function
mgimple 0:61f876d07ef5 21
mgimple 0:61f876d07ef5 22 int main()
mgimple 0:61f876d07ef5 23 {
mgimple 1:d706fb07041f 24 while(1) {
mgimple 1:d706fb07041f 25 void temp_read(); //main temperature reading command to be called upon
mgimple 1:d706fb07041f 26 {
mgimple 1:d706fb07041f 27 volt_raw = therm.read(); //sets the raw data as a variable
mgimple 1:d706fb07041f 28 volt = volt_raw*3.3; //converts raw voltage to the correct scale for our mbed
mgimple 1:d706fb07041f 29 temp = -1481.96+sqrt(((2.1962e6)+((1.8639-volt)/(3.88e-6)))); //converts voltage to temperature
mgimple 1:d706fb07041f 30 pc.printf("TEMP %f Volts %3.1f Celsius \r\n",volt, temp);
mgimple 1:d706fb07041f 31 wait(1);
mgimple 1:d706fb07041f 32 if (temp<50) {
mgimple 0:61f876d07ef5 33
mgimple 1:d706fb07041f 34 if (temp>=20) {
mgimple 1:d706fb07041f 35 Led1=1;
mgimple 1:d706fb07041f 36 if (temp>=25) {
mgimple 1:d706fb07041f 37 Led2=1;
mgimple 1:d706fb07041f 38 if (temp>=30) {
mgimple 1:d706fb07041f 39 Led3=1;
mgimple 1:d706fb07041f 40 }
mgimple 0:61f876d07ef5 41 }
mgimple 0:61f876d07ef5 42 }
mgimple 0:61f876d07ef5 43 }
mgimple 0:61f876d07ef5 44 }
mgimple 0:61f876d07ef5 45
mgimple 1:d706fb07041f 46 void light_read(); //main light reading command to be called upon
mgimple 1:d706fb07041f 47 {
mgimple 1:d706fb07041f 48 light_volt_raw=light.read(); //sets the raw data as a variable
mgimple 1:d706fb07041f 49 light_res=(10000/light_volt_raw)-10000; //converting voltage to resistance
mgimple 1:d706fb07041f 50 light_volt=light_volt_raw*3.3; //mbed outputs 3.3 volts
mgimple 1:d706fb07041f 51 pc.printf("LIGHT %1.3f Voltz 6.2%f Ohms\r\n",light_volt,light_res);
mgimple 1:d706fb07041f 52 wait(1);
mgimple 1:d706fb07041f 53 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
mgimple 1:d706fb07041f 54 Led4=1;
mgimple 1:d706fb07041f 55 }
mgimple 1:d706fb07041f 56 if (light_volt>0.3) {
mgimple 1:d706fb07041f 57 Led4=0;
mgimple 1:d706fb07041f 58 }
mgimple 0:61f876d07ef5 59 }
mgimple 1:d706fb07041f 60
mgimple 0:61f876d07ef5 61 }
mgimple 0:61f876d07ef5 62 }