Uređaj za nadzor temperature, koristi temperaturni senzor koji mjeri temperaturu. Na LCD-u se ispisuje mjerena temperatura te ovisno o rasponu temperature ispisuje se "Prohladno", "Toplo", "Vruce". Korisnik ima mogućnost uključenja ventilatora pomoći tipkala te postoje i signalne diode koje korisniku signaliziraju da li je ventilator uključen, nije uključen te kada je potrebno uključiti ventilator upravljan preko releja.
main.cpp
00001 #include "mbed.h" 00002 #include "Signal.h" 00003 #include "TextLCD.h" 00004 00005 Signal led4(PB_4); 00006 AnalogIn LM35(PA_0); 00007 DigitalOut led1(PA_8); 00008 DigitalOut led2(PB_3); 00009 DigitalOut led3(PA_5); 00010 DigitalOut fan(PA_6); 00011 InterruptIn button(PB_10); 00012 Timer debounce; 00013 Ticker signal; 00014 TextLCD lcd(PA_10,PB_5,PA_9,PC_7,PB_6,PA_7); //RS,E,D4,D5,D6,D7 00015 00016 void toggle(void); 00017 float temperature(float value); 00018 00019 void signal_diode() 00020 { 00021 led2 = !led2; 00022 } 00023 00024 float temperature(float value) 00025 { 00026 float temp; 00027 float Vout; 00028 int Vref = 5000; 00029 Vout = (value * Vref); 00030 temp = (Vout/10); 00031 return temp; 00032 } 00033 00034 int main() 00035 { 00036 float value; 00037 float T; 00038 char c = '.'; 00039 int i; 00040 button.mode(PullUp); 00041 debounce.start(); 00042 button.rise(&toggle); 00043 led2 = 0; 00044 led3 = 1; 00045 signal.attach(&signal_diode, 1); 00046 for (i = 7; i < 16; i++) { 00047 lcd.locate(0,0); 00048 lcd.printf("LOADING"); 00049 lcd.locate(0,1); 00050 lcd.printf("Please wait."); 00051 lcd.locate(i,0); 00052 lcd.printf("%c", c); 00053 wait(0.5); 00054 } 00055 while(1) { 00056 lcd.cls(); 00057 lcd.printf("Temp:"); 00058 value = LM35.read(); 00059 T = temperature(value); 00060 lcd.locate(6,0); 00061 lcd.printf("%.2f C",T); 00062 if (T < 18) { 00063 lcd.locate(3,1); 00064 lcd.printf("Prohladno!"); 00065 led4.light(0); 00066 } else if (T >= 18 && T < 24) { 00067 lcd.locate(5,1); 00068 lcd.printf("Toplo!"); 00069 led4.light(1); 00070 } else if (T >= 24) { 00071 lcd.locate(5,1); 00072 lcd.printf("Vruce!"); 00073 led4.light(2); 00074 } 00075 wait(1); 00076 } 00077 } 00078 00079 void toggle() 00080 { 00081 if (debounce.read_ms()>200) 00082 fan=!fan; 00083 if (fan) { 00084 lcd.cls(); 00085 led1 = 1; 00086 led3 = 0; 00087 lcd.locate(0,0); 00088 lcd.printf("Fan: ON"); 00089 wait(1); 00090 } else { 00091 lcd.cls(); 00092 led1 = 0; 00093 led3 = 1; 00094 lcd.locate(0,0); 00095 lcd.printf("Fan: OFF"); 00096 wait(1); 00097 } 00098 debounce.reset(); 00099 } 00100
Generated on Sun Nov 27 2022 12:37:56 by
1.7.2