sicaklik mesafe okuma

Dependencies:   mbed mbed-rtos TextLCD DHT11

Revision:
3:90c2a3485cf6
Parent:
2:f6e831d1901e
--- a/main.cpp	Wed Oct 23 08:25:50 2019 +0000
+++ b/main.cpp	Wed Oct 23 08:50:28 2019 +0000
@@ -1,15 +1,18 @@
 
 #include "mbed.h"
-#include "hcsr04.h"
+
 #include "TextLCD.h"
 #include "rtos.h"
 #include "DHT11.h"
 #include <iostream>
+Timer sure;
 TextLCD lcd(D11, D12, D7, D8, D9, D10); // rs, e, d4-d7
 DigitalOut buzzer(A0);
-   HCSR04 sensor(D5, D6); 
+DigitalIn echo(D6);
+DigitalOut trig(D5);
 Thread msf,dht_11;
 DHT11 t(D3);
+long mesafe;
 volatile long x;//bu değişken bütün threadlerde çalışır
 volatile char sicaklik,nem;
 void sicaklikmetodu()
@@ -21,7 +24,7 @@
              nem=t.readHumidity();
 cout<<"Sicaklik:"<<t.readTemperature()<<" Nem:%"<<t.readHumidity()<<endl;
 lcd.locate(0,1);
-lcd.printf("S:%c N:%c", sicaklik,nem);
+lcd.printf("S:%d N:%d", sicaklik,nem);
 wait(2);
         
         }
@@ -50,14 +53,25 @@
     msf.start(mesafemetodu);
     dht_11.start(sicaklikmetodu);
     while(1) {
-        
-    long distance = sensor.distance(); 
-    x= distance;
-     if( distance<200)
+  sure.reset();
+        trig=0;
+        wait_us(5);
+        trig=1;
+        wait_us(10);
+        sure.start();
+        trig=0;
+         while(!echo); // start pulseIN
+      sure.start();
+     while(echo);
+      sure.stop();
+        mesafe=sure.read_us()/58.2;
+        printf("%f cm \n",mesafe);
+        x=mesafe;
+     if( mesafe<200)
      {
-      printf("Mesafe  %d  \n",distance);
+      printf("Mesafe  %d  \n",mesafe);
       lcd.locate(0,0);
-      lcd.printf("Mesafe %dcm",distance);
+      lcd.printf("Mesafe %d cm",mesafe);
       lcd.printf("   ");
       }
       wait_ms(200); // 1 sec