Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos TextLCD DHT11
Revision 3:90c2a3485cf6, committed 2019-10-23
- Comitter:
- marvas
- Date:
- Wed Oct 23 08:50:28 2019 +0000
- Parent:
- 2:f6e831d1901e
- Commit message:
- en son
Changed in this revision
| HCSR04.lib | Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HCSR04.lib Wed Oct 23 08:25:50 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/antoniolinux/code/HCSR04/#86b2086be101
--- 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