temp sensor with 7 segment display

Dependencies:   mbed

Committer:
jakebonney10
Date:
Thu Oct 12 14:45:41 2017 +0000
Revision:
0:04ec3b386f53
tmp36;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jakebonney10 0:04ec3b386f53 1 //Assignment 3
jakebonney10 0:04ec3b386f53 2 //Jake Bonney
jakebonney10 0:04ec3b386f53 3 //OCE 360
jakebonney10 0:04ec3b386f53 4
jakebonney10 0:04ec3b386f53 5 //Display temp sensor output to serial terminal connection in Fahrenheit
jakebonney10 0:04ec3b386f53 6 //Turn on leds for specific temperature outputs
jakebonney10 0:04ec3b386f53 7
jakebonney10 0:04ec3b386f53 8 #include "mbed.h"
jakebonney10 0:04ec3b386f53 9
jakebonney10 0:04ec3b386f53 10 Serial pc(USBTX, USBRX); //serial connection
jakebonney10 0:04ec3b386f53 11 AnalogIn TMP36(p15); // Temp sensor
jakebonney10 0:04ec3b386f53 12 DigitalOut myled1(LED1); //internal led
jakebonney10 0:04ec3b386f53 13 DigitalOut myled2(LED2); //internal led
jakebonney10 0:04ec3b386f53 14 DigitalOut myled3(LED3); //internal led
jakebonney10 0:04ec3b386f53 15 DigitalOut myled4(LED4); //internal led
jakebonney10 0:04ec3b386f53 16 PwmOut red_led(p21);
jakebonney10 0:04ec3b386f53 17 BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12); // ABCDEFGDP 7 segment display
jakebonney10 0:04ec3b386f53 18
jakebonney10 0:04ec3b386f53 19 int main() {
jakebonney10 0:04ec3b386f53 20 float tempC, tempF;
jakebonney10 0:04ec3b386f53 21
jakebonney10 0:04ec3b386f53 22 while(1) {
jakebonney10 0:04ec3b386f53 23 //conversion to degrees C celcius from TMP36 output
jakebonney10 0:04ec3b386f53 24 tempC = (((TMP36*3.3)*30.0)-15.0);
jakebonney10 0:04ec3b386f53 25 //convert to degrees F fahrenheit
jakebonney10 0:04ec3b386f53 26 tempF = (9.0*tempC)/5.0 + 32.0;
jakebonney10 0:04ec3b386f53 27 //print current temp to serial output
jakebonney10 0:04ec3b386f53 28 printf("%5.2F C %5.2F F \n\r", tempC, tempF);
jakebonney10 0:04ec3b386f53 29 wait(.5);
jakebonney10 0:04ec3b386f53 30
jakebonney10 0:04ec3b386f53 31 if (tempF <=30){
jakebonney10 0:04ec3b386f53 32 //tempF is below 0...no internal leds on
jakebonney10 0:04ec3b386f53 33 myled1=0;
jakebonney10 0:04ec3b386f53 34 myled2=0;
jakebonney10 0:04ec3b386f53 35 myled3=0;
jakebonney10 0:04ec3b386f53 36 myled4=0;
jakebonney10 0:04ec3b386f53 37 Seg1=0x3F; // 00111111 binary LEDs to '0'
jakebonney10 0:04ec3b386f53 38 red_led.write(0.0f);
jakebonney10 0:04ec3b386f53 39 }
jakebonney10 0:04ec3b386f53 40 else if (tempF > 30 and tempF <= 50){
jakebonney10 0:04ec3b386f53 41 //tempF is between 0 and 30...led1 is on
jakebonney10 0:04ec3b386f53 42 myled1=1;
jakebonney10 0:04ec3b386f53 43 myled2=0;
jakebonney10 0:04ec3b386f53 44 myled3=0;
jakebonney10 0:04ec3b386f53 45 myled4=0;
jakebonney10 0:04ec3b386f53 46 Seg1=0x06; // 00000110 binary LEDs to '1'
jakebonney10 0:04ec3b386f53 47 red_led.write(0.25f);
jakebonney10 0:04ec3b386f53 48 }
jakebonney10 0:04ec3b386f53 49 else if (tempF > 50 and tempF <= 70){
jakebonney10 0:04ec3b386f53 50 //tempF is between 30 and 60...leds 1/2 are on
jakebonney10 0:04ec3b386f53 51 myled1=1;
jakebonney10 0:04ec3b386f53 52 myled2=1;
jakebonney10 0:04ec3b386f53 53 myled3=0;
jakebonney10 0:04ec3b386f53 54 myled4=0;
jakebonney10 0:04ec3b386f53 55 Seg1=0x5B; // 01011011 binary LEDs to '2'
jakebonney10 0:04ec3b386f53 56 red_led.write(0.5f);
jakebonney10 0:04ec3b386f53 57 }
jakebonney10 0:04ec3b386f53 58 else if (tempF > 70 and tempF <= 90){
jakebonney10 0:04ec3b386f53 59 //tempF is between 60 and 100...leds 1/2/3 are on
jakebonney10 0:04ec3b386f53 60 myled1=1;
jakebonney10 0:04ec3b386f53 61 myled2=1;
jakebonney10 0:04ec3b386f53 62 myled3=1;
jakebonney10 0:04ec3b386f53 63 myled4=0;
jakebonney10 0:04ec3b386f53 64 Seg1=0x4F; // 01001111 binary LEDs to '3'
jakebonney10 0:04ec3b386f53 65 red_led.write(0.75f);
jakebonney10 0:04ec3b386f53 66
jakebonney10 0:04ec3b386f53 67 }
jakebonney10 0:04ec3b386f53 68 else if (tempF > 90){
jakebonney10 0:04ec3b386f53 69 //tempF is greater than 100...all leds are on
jakebonney10 0:04ec3b386f53 70 myled1=1;
jakebonney10 0:04ec3b386f53 71 myled2=1;
jakebonney10 0:04ec3b386f53 72 myled3=1;
jakebonney10 0:04ec3b386f53 73 myled4=1;
jakebonney10 0:04ec3b386f53 74 Seg1=0x66; // 01100110 binary LEDs to '4'
jakebonney10 0:04ec3b386f53 75 red_led.write(1.0f);
jakebonney10 0:04ec3b386f53 76 }
jakebonney10 0:04ec3b386f53 77 }
jakebonney10 0:04ec3b386f53 78 }