Ultrasonic sensor kullanimi Hcsr04 Mehmet Akif ARVAS

Files at this revision

API Documentation at this revision

Comitter:
marvas
Date:
Sun Dec 09 08:39:57 2018 +0000
Commit message:
By Mehmet Akif ARVAS Ultrasonic Sensor in Turkish

Changed in this revision

hcsr04.cpp Show annotated file Show diff for this revision Revisions of this file
hcsr04.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 530d4c35d92a hcsr04.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.cpp	Sun Dec 09 08:39:57 2018 +0000
@@ -0,0 +1,32 @@
+#include "hcsr04.h"
+#include "mbed.h"
+/*
+
+HCSR04 Ultrasonik sensör kullanýmý
+Mehmet Akif Arvas
+Herkese açýktýr. Telif hakký yoktur. :))
+*/
+HCSR04::HCSR04(PinName t, PinName e) : trig(t), echo(e) {}
+ int HCSR04::echo_sure() {
+        
+    timer.reset();  //reset timer
+    trig=0;   // trigger low 
+    wait_us(2); //  wait 
+    trig=1;   //  trigger high
+    wait_us(10);
+    trig=0;  // trigger low
+         while(!echo); // start pulseIN
+      timer.start();
+     while(echo);
+      timer.stop();
+     return timer.read_us(); 
+ 
+}
+ 
+//return distance in cm 
+int HCSR04::uzaklik(){
+    sure = echo_sure();
+ mesafe_cm = (sure/2)/29.1  ;
+        return mesafe_cm;
+
+}
\ No newline at end of file
diff -r 000000000000 -r 530d4c35d92a hcsr04.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.h	Sun Dec 09 08:39:57 2018 +0000
@@ -0,0 +1,38 @@
+/* File: HCSR04.h
+Mehmet Akif Arvas
+*/
+#include "mbed.h"
+#include "hcsr04.h"
+
+//D12 TRIGGER D11 ECHO
+   HCSR04 sensor(D12, D11); 
+int main() {
+    while(1) {
+        
+     long distance = sensor.distance();   
+      printf("distanza  %d  \n",distance);
+      wait(1.0); // 1 sec  
+        
+    }
+}
+*/
+#ifndef hcsr04_H
+#define hcsr04_H
+#include "mbed.h"
+
+
+ 
+class HCSR04 {
+  public:
+    HCSR04(PinName t, PinName e);
+    int echo_sure();
+    int uzaklik();
+ 
+    private:
+        DigitalOut trig;
+        DigitalIn echo;
+        Timer timer;
+        int sure,mesafe_cm;
+};
+ 
+#endif
\ No newline at end of file