sicaklik mesafe okuma

Dependencies:   mbed mbed-rtos TextLCD DHT11

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 
00004 #include "TextLCD.h"
00005 #include "rtos.h"
00006 #include "DHT11.h"
00007 #include <iostream>
00008 Timer sure;
00009 TextLCD lcd(D11, D12, D7, D8, D9, D10); // rs, e, d4-d7
00010 DigitalOut buzzer(A0);
00011 DigitalIn echo(D6);
00012 DigitalOut trig(D5);
00013 Thread msf,dht_11;
00014 DHT11 t(D3);
00015 long mesafe;
00016 volatile long x;//bu değişken bütün threadlerde çalışır
00017 volatile char sicaklik,nem;
00018 void sicaklikmetodu()
00019 {
00020     while(1)
00021     {
00022          t.readData();
00023              sicaklik= t.readTemperature();
00024              nem=t.readHumidity();
00025 cout<<"Sicaklik:"<<t.readTemperature()<<" Nem:%"<<t.readHumidity()<<endl;
00026 lcd.locate(0,1);
00027 lcd.printf("S:%d N:%d", sicaklik,nem);
00028 wait(2);
00029         
00030         }
00031     }
00032 void mesafemetodu()
00033 {
00034       while(1)
00035       {
00036       if(x<50)
00037       {
00038           buzzer=1;
00039           wait(300);
00040           buzzer=0;
00041            wait(300);
00042           }
00043           else
00044           {
00045               buzzer=0;
00046               }
00047         
00048           }
00049     }
00050 
00051 int main() {
00052   
00053     msf.start(mesafemetodu);
00054     dht_11.start(sicaklikmetodu);
00055     while(1) {
00056   sure.reset();
00057         trig=0;
00058         wait_us(5);
00059         trig=1;
00060         wait_us(10);
00061         sure.start();
00062         trig=0;
00063          while(!echo); // start pulseIN
00064       sure.start();
00065      while(echo);
00066       sure.stop();
00067         mesafe=sure.read_us()/58.2;
00068         printf("%f cm \n",mesafe);
00069         x=mesafe;
00070      if( mesafe<200)
00071      {
00072       printf("Mesafe  %d  \n",mesafe);
00073       lcd.locate(0,0);
00074       lcd.printf("Mesafe %d cm",mesafe);
00075       lcd.printf("   ");
00076       }
00077       wait_ms(200); // 1 sec  
00078         
00079     }
00080 }
00081 /*
00082 
00083 
00084 #include "mbed.h"
00085 
00086 DigitalOut trig(D5);
00087 DigitalIn echo(D6);
00088 Timer sure;
00089 float mesafe;
00090 
00091 int main()
00092 {
00093     while(1)
00094     {
00095         trig=0;
00096         wait_us(5);
00097         trig=1;
00098         wait_us(10);
00099         sure.start();
00100         trig=0;
00101         while(1)
00102         {
00103          if(echo==1)
00104          {
00105         sure.stop();
00106         break;
00107         }
00108         }
00109         mesafe=sure.read()/58.2;
00110         printf("%f cm \n",mesafe);
00111         sure.reset();
00112 
00113        }
00114     }
00115     */