Sample Code for RDC EET214 Lab3
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 //Sample Code for EET214 Lab3 Thermostat 00002 00003 #include "mbed.h" 00004 00005 DigitalOut furnace(LED4); //use LED4 to simualte furnace 00006 AnalogIn room_T(p20); //Use pin 20 to read room temperature 00007 int iRoom_T = 0; //Room Temperature in integer 00008 int iRoom_T_One = 0; //Temperature number at one digit 00009 int iRoom_T_Ten = 0; //Temperature number at ten digit 00010 00011 int display10( int iRoom_T_Ten); //Function to display ten digits 00012 int display1( int iRoom_T_One); //Function to display one digits 00013 00014 BusOut displayA(p5, p6, p7, p8, p9, p10, p11, p12); //Use P5 - P12 for Display 1 00015 BusOut displayB(p21,p22,p23,p24,p25,p26, p27, p28); //Use P21- P28 for display 2 00016 00017 int main() { 00018 while(1) { 00019 00020 //Read sensor and convert the value into integer 00021 iRoom_T = (int)(( room_T * 3.3 ) /0.01 ); 00022 iRoom_T = 21; //Testing code 00023 00024 //Display Room Temperature 00025 iRoom_T_Ten = iRoom_T / 10; //Get number at ten digits 00026 iRoom_T_One = iRoom_T % 10; //Get number at one digits 00027 00028 display10(iRoom_T_Ten); //Display ten digits 00029 display1(iRoom_T_One); //Display one digits 00030 00031 //Turn on / off furnace according to temperature 00032 if(iRoom_T > 27) //Over 27 C 00033 furnace = 0; //Turn furnace off 00034 if(iRoom_T < 25) //Below 25C 00035 furnace = 1; //Turn furnace on 00036 00037 wait(1); //Wait for 1 second 00038 } // End of while(1) 00039 } 00040 00041 //Display number at TEN digits 00042 int display10( int iRoom_T_Ten) 00043 { 00044 switch(iRoom_T_Ten) 00045 { 00046 case 0: 00047 //displayA = 0x3f; //Common Cathode 00048 displayA = 0xC0; //Common Anode 00049 break; 00050 00051 case 1: 00052 // displayA = 0x3f; 00053 break; 00054 00055 case 2: 00056 //displayA = 0x5B; //Common Cathode 00057 displayA = 0xA4; //Common Anode 00058 break; 00059 00060 00061 default: 00062 // displayA = 0x00; 00063 break; 00064 } 00065 00066 return 1; 00067 } 00068 00069 //Display number at ONE digits 00070 int display1( int iRoom_T_One) 00071 { 00072 switch(iRoom_T_One) 00073 { 00074 case 0: 00075 //displayB = 0x3f; //Common Cathode 00076 displayB = 0xC0; //Common Anode 00077 break; 00078 00079 case 1: 00080 //displayB = 0x06; //Common Cathode 00081 displayB = 0xf9; //Common anode 00082 break; 00083 00084 00085 00086 default: 00087 // displayB = 0x00; 00088 break; 00089 } 00090 00091 return 1; 00092 }
Generated on Fri Jul 15 2022 04:50:06 by
1.7.2