Yuliang Hao
/
Thermostat
Sample Code for RDC EET214 Lab3
main.cpp
- Committer:
- YuliangHao
- Date:
- 2017-09-27
- Revision:
- 4:c654bdf271fc
- Parent:
- 3:f2026b3d5763
File content as of revision 4:c654bdf271fc:
//Sample Code for EET214 Lab3 Thermostat #include "mbed.h" DigitalOut furnace(LED4); //use LED4 to simualte furnace AnalogIn room_T(p20); //Use pin 20 to read room temperature int iRoom_T = 0; //Room Temperature in integer int iRoom_T_One = 0; //Temperature number at one digit int iRoom_T_Ten = 0; //Temperature number at ten digit int display10( int iRoom_T_Ten); //Function to display ten digits int display1( int iRoom_T_One); //Function to display one digits BusOut displayA(p5, p6, p7, p8, p9, p10, p11, p12); //Use P5 - P12 for Display 1 BusOut displayB(p21,p22,p23,p24,p25,p26, p27, p28); //Use P21- P28 for display 2 int main() { while(1) { //Read sensor and convert the value into integer iRoom_T = (int)(( room_T * 3.3 ) /0.01 ); iRoom_T = 21; //Testing code //Display Room Temperature iRoom_T_Ten = iRoom_T / 10; //Get number at ten digits iRoom_T_One = iRoom_T % 10; //Get number at one digits display10(iRoom_T_Ten); //Display ten digits display1(iRoom_T_One); //Display one digits //Turn on / off furnace according to temperature if(iRoom_T > 27) //Over 27 C furnace = 0; //Turn furnace off if(iRoom_T < 25) //Below 25C furnace = 1; //Turn furnace on wait(1); //Wait for 1 second } // End of while(1) } //Display number at TEN digits int display10( int iRoom_T_Ten) { switch(iRoom_T_Ten) { case 0: //displayA = 0x3f; //Common Cathode displayA = 0xC0; //Common Anode break; case 1: // displayA = 0x3f; break; case 2: //displayA = 0x5B; //Common Cathode displayA = 0xA4; //Common Anode break; default: // displayA = 0x00; break; } return 1; } //Display number at ONE digits int display1( int iRoom_T_One) { switch(iRoom_T_One) { case 0: //displayB = 0x3f; //Common Cathode displayB = 0xC0; //Common Anode break; case 1: //displayB = 0x06; //Common Cathode displayB = 0xf9; //Common anode break; default: // displayB = 0x00; break; } return 1; }