.

Dependencies:   HCSR04v2 Servo mbed

Fork of CZOSINHO by Dominik Święch

Files at this revision

API Documentation at this revision

Comitter:
yruiewyrui3
Date:
Tue Jun 21 09:19:17 2016 +0000
Parent:
1:b57f208d1d95
Commit message:
.

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b57f208d1d95 -r 26a9f90142a0 HCSR04.lib
--- a/HCSR04.lib	Tue Jun 21 07:46:37 2016 +0000
+++ b/HCSR04.lib	Tue Jun 21 09:19:17 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/yruiewyrui3/code/HCSR04/#0b3bdb910fe7
+https://developer.mbed.org/users/yruiewyrui3/code/HCSR04v2/#8c633a86ddb5
diff -r b57f208d1d95 -r 26a9f90142a0 main.cpp
--- a/main.cpp	Tue Jun 21 07:46:37 2016 +0000
+++ b/main.cpp	Tue Jun 21 09:19:17 2016 +0000
@@ -23,7 +23,8 @@
 int po=0;
 int pi=0;
 Timer t, t_sonar;
-float distance;
+long distance;
+
  
 //*************** Funkcja czyszczaca bufor *****************
 void cleanBuffer(char *buffor)
@@ -146,17 +147,18 @@
     int i = 0;
     cleanBuffer(bufor);
     stm.baud(115200);
+    t_sonar.start();
     while(true){
         if(t.read_ms()>200){ //jesli przez ponad 200ms nie ma nowej ramki, zatrzymujemy robota
             eng_left.move(0);
             eng_right.move(0);
             }
         if(t_sonar.read_ms()>1200){
+            distance = sensor.distance(); 
+            stm.printf("dystans  %d  \n",distance);
             t_sonar.stop();
             t_sonar.reset();
             t_sonar.start(); 
-            distance = sensor.distance(); 
-            stm.printf("dystans  %d  \n",distance);  
             }
         if(bufor[9] == NULL){
             bufor[i] = stm.getc();