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:
- michael_antonucci
- Date:
- 2022-11-16
- Revision:
- 0:966ecf8af5b3
File content as of revision 0:966ecf8af5b3:
#include "mbed.h"
//Assignment 5, Exercise 1
//Author: Michael Antonucci
//Date Modified: 11/15/22
DigitalOut LEDOut1(LED1); //digital output to LED1
DigitalOut LEDOut2(LED2); //digital output to LED2
DigitalOut LEDOut3(LED3); //digital output to LED3
DigitalOut LEDOut4(LED4); //digital output to LED4
Timer out_timer; //timer
AnalogIn therm(p19); //thermistor
AnalogIn photo(p20); //photocell
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
float thermistor_volt(AnalogIn therm)
{
float temp_v; // thermistor voltage
temp_v=therm.read()*3.3; // thermistor output
return temp_v;
}
float photocell_resistance(AnalogIn photo)
{
float photo_v;
photo_v=photo.read()*3.3; // photocell output
if (photo_v<1.8) {
LEDOut4=1;
} else {
LEDOut4=0;
}
return photo_v;
}
float thermistor_temp(AnalogIn therm)
{
float temp;
temp= -1481.96+sqrt((2196200)+((1.8639-(3.3*therm.read()))/0.00000388)); // voltage to degrees C
if(temp>=13) {
LEDOut1=1;
} else {
LEDOut1=0;
}
if(temp>=20) {
LEDOut2=1;
} else {
LEDOut2=0;
}
if(temp>=27) {
LEDOut3=1;
} else {
LEDOut3=0;
}
return temp;
}
int main()
{
DigitalOut LEDOut1(LED1); //digital output to LED1
DigitalOut LEDOut2(LED2); //digital output to LED2
DigitalOut LEDOut3(LED3); //digital output to LED3
DigitalOut LEDOut4(LED4); //digital output to LED4
float temp; // temperature, thermistor
float temp_v; // voltage of thermistor
float photo_v; // voltage of photocell
while(1) {
temp = thermistor_temp(therm);
temp_v = thermistor_volt(therm);
photo_v = photocell_resistance(photo);
out_timer.start();
if(out_timer.read()>1) {
pc.printf("Thermistor Voltage: %f Volts \r\n Temperature: %f Celsius \r\n Photocell Voltage: %f Volts \r\n ",temp_v,temp,photo_v);
out_timer.reset();
}
}
}
