Mali mjerač temperature koji očitava temperaturu okoline pomoću LM35 senzora, ispisuje ju na 16x2 LCD displej te serijski na računalo. LED dioda blica ovisno o temperaturi(veća temperatura=brže blicanje) te tipkalom upravljamo osvjetljenjem LCDa.

Dependencies:   LM35 TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //libraryji
00002 #include "mbed.h"
00003 #include "LM35.h"
00004 #include "TextLCD.h"
00005 
00006 
00007 InterruptIn button(USER_BUTTON); //okidač interrupt rutine
00008 Timer debounce;    //timer za istitravanje tastera
00009 TextLCD lcd (PC_8, PB_8, PC_6, PC_5, PA_12, PA_11); //pinovi LCDa
00010 Ticker ledtemp;     //Ticker za blicanje ledice
00011 Timer timer1;       //timer korišten u mainu
00012 DigitalOut led1(PA_10);    //ledica
00013 Serial pc(USBTX, USBRX);    //serijska komunikacija s računalom
00014 LM35 senzor(PC_0);          //senzor temperature
00015 float temperatura2;         //inicijalizacija varijable
00016 void interrupt (void);      //inicijalizacija funkcije
00017 DigitalOut svjetlo(PB_5);   //osvjetljenje LCDa
00018 
00019 //interupt funkcija
00020 void interrupt()
00021 {
00022     if (debounce.read_ms()>200) {
00023 
00024         svjetlo=!svjetlo;
00025     }
00026 
00027 }
00028 
00029 //funkcija za blicanje ledica, tj. mijenjanje stanja ledice
00030 void ledica()
00031 {
00032     led1=!led1;
00033 
00034 }
00035 
00036 
00037 //funkcija za određivanje frekvencije tickera, tj.frekvencije blicanja ledice
00038 void vizualizacija()
00039 {
00040 
00041     if (temperatura2 > 15 && temperatura2 < 20)
00042         ledtemp.attach(&ledica, 0.5);
00043     else if (temperatura2> 20 && temperatura2 < 25)
00044         ledtemp.attach(&ledica, 0.25);
00045     else if (temperatura2 > 25)
00046         ledtemp.attach(&ledica, 0.15);
00047     else  led1=0;
00048 
00049 
00050 }
00051 
00052 //glavna funkcija
00053 int main()
00054 {
00055     debounce.start();
00056     timer1.start();
00057     button.rise(&interrupt);
00058     while(1) {
00059         if(timer1.read_ms()>=1000) {
00060             temperatura2 = senzor.mjerenje();
00061             lcd.cls ();
00062             lcd.printf("Temperatura je:", temperatura2);
00063             lcd.locate (0,1);
00064             lcd.printf("%.2f C", temperatura2);
00065             vizualizacija();
00066             timer1.reset();
00067         }
00068 
00069 
00070     }
00071 }
00072 
00073