Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- mgimple
- Date:
- 2021-10-29
- Revision:
- 3:0170897aa173
- Parent:
- 2:38d752717527
File content as of revision 3:0170897aa173:
#include "mbed.h" #include "math.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 int main() { while(1) { 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); if (temp>=15 && temp<20) { Led1=1; } if (temp<15 && 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; } } }