sub

Dependencies:   HCSR04 mbed

Fork of Cat_Bot_sub by kazuki ishibashi

Files at this revision

API Documentation at this revision

Comitter:
UCHITAKE
Date:
Thu Mar 23 06:45:42 2017 +0000
Parent:
1:f4ae12a86f80
Commit message:
newLPC2NUCLEO_SERIAL

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f4ae12a86f80 -r 3f2d37164a10 main.cpp
--- a/main.cpp	Fri Feb 03 10:34:43 2017 +0000
+++ b/main.cpp	Thu Mar 23 06:45:42 2017 +0000
@@ -2,18 +2,29 @@
 #include "hcsr04.h"
 
 Serial to_main(dp4,dp5);
-//Serial pc(USBTX,USBRX);
 
 HCSR04 front(dp24,dp25);
 HCSR04 back(dp22,dp23);
 HCSR04 right(dp20,dp21);
 HCSR04 left(dp18,dp19);
 
+Ticker tick;
 
+char dist[4]= {0};
 
-int main() {
-    char dist[4]={0};
-    //to_main.baud(19200);
+void put()
+{
+    to_main.putc(1);
+    to_main.putc(dist[0]);
+    to_main.putc(dist[1]);
+    to_main.putc(dist[2]);
+    to_main.putc(dist[3]);
+}
+
+int main()
+{
+    to_main.baud(9600);
+    tick.attach(&put, 0.05);
     while(1) {
         front.start();
         back.start();
@@ -35,11 +46,5 @@
             dist[3]=255;
         else
             dist[3]=left.get_dist_cm();
-
-        to_main.putc(1);
-        for(int i=0;i<4;i++){
-            to_main.putc(dist[i]);
-        }
-        //pc.putc('\n');
     }
 }