Bryan Bates
/
TempControlFan
Temperature controlled fan with hysteresis cooling
Revision 0:f3f670fbc25d, committed 2016-12-08
- Comitter:
- bryanbates
- Date:
- Thu Dec 08 19:58:11 2016 +0000
- Commit message:
- Final Project for 4180
Changed in this revision
diff -r 000000000000 -r f3f670fbc25d Motor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Thu Dec 08 19:58:11 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r f3f670fbc25d TMP36.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TMP36.h Thu Dec 08 19:58:11 2016 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" + +//Setup a new class for TMP36 sensor +class TMP36 +{ +public: + TMP36(PinName pin); + TMP36(); + operator float (); + float read(); +private: +//class sets up the AnalogIn pin + AnalogIn _pin; +}; + +TMP36::TMP36(PinName pin) : _pin(pin) +{ +// _pin(pin) means pass pin to the AnalogIn constructor +} + +float TMP36::read() +{ +//convert sensor reading to temperature in degrees C + return ((_pin.read()*3.3)-0.500)*100.0; +} +//overload of float conversion (avoids needing to type .read() in equations) +TMP36::operator float () +{ +//convert sensor reading to temperature in degrees C + return ((_pin.read()*3.3)-0.500)*100.0; +} \ No newline at end of file
diff -r 000000000000 -r f3f670fbc25d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 08 19:58:11 2016 +0000 @@ -0,0 +1,48 @@ +#include "mbed.h" +#include "TMP36.h" +#include "Motor.h" +#include <math.h> + +TMP36 tempSensor(p15); // Uses TMP36.h to display temperature in Celcius +Serial xbee1(p28, p27); // TX, RX +Motor m(p21, p19, p20); // pwm, fwd, rev +DigitalOut rst(p11); // RST (RESET) +DigitalOut redLED(p5); + + + + +char *float2str(float float_num); + +int main(){ + rst = 0; + wait_ms(1); + rst = 1; + wait_ms(1); + + float temp = 0.0; + float fanspeed; + float fanratio; + + xbee1.baud(9600); + + while (1){ + temp = tempSensor; + if (temp > 26.0){ + fanratio = temp/26; + fanspeed = exp(fanratio) - 2.2; + redLED = 1; + } + else{ + fanspeed = 0.0; + redLED = 0; + } + m.speed(fanspeed); + + xbee1.printf("%.1f\n\r",temp); + wait(1); + } + +} + + \ No newline at end of file
diff -r 000000000000 -r f3f670fbc25d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 08 19:58:11 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file