部ロボ受信機のプログラムです。

Dependencies:   mbed HCSR04

Files at this revision

API Documentation at this revision

Comitter:
WAT34
Date:
Mon Jan 12 01:02:24 2015 +0000
Parent:
2:5c47df2771ec
Commit message:
????4????????????????????

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 5c47df2771ec -r 43e85adf8768 HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Mon Jan 12 01:02:24 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/antoniolinux/code/HCSR04/#86b2086be101
diff -r 5c47df2771ec -r 43e85adf8768 main.cpp
--- a/main.cpp	Sat Jan 10 05:30:58 2015 +0000
+++ b/main.cpp	Mon Jan 12 01:02:24 2015 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
 
+DigitalOut trig(p19);
+DigitalOut echo(p20);
 Serial pc(USBTX,USBRX);
 Serial trans(p9,p10);
 DigitalOut myled(LED1);
@@ -8,6 +10,7 @@
 PwmOut m1(p21);
 PwmOut m2(p22);
 BusOut updown(p27,p28);
+BusOut slidem(p17,p18);
 void move(int a,int b,int c,int d)
 {
     int width = 5.0;
@@ -16,9 +19,10 @@
     int l = 6;
     int r = 9;
     int stop = 0;
-    double mp1,mp2;
+    double mp1,mp2,mp3;
     mp1 = (c-1)/100.0;
     mp2 = 1.0-((d-1)/100.0);
+    mp3 = (d/100.0);
     //pc.printf("mp1*mp2--->%f\n\r",mp1*mp2);
     //pc.printf("mp1--->%f",mp1);
     if(d>b+width)
@@ -42,12 +46,12 @@
         if(c>b+width)
         {
             mc = seiten;
-            m1 = 1-mp1*mp2;
+            m1 = mp1*mp3;
             m2 = mp1;
         }else if(c<b-width)
         {
            mc = gyaku;
-           m2 = 1-(1-mp1)*mp2;
+           m2 = (1-mp1)*mp3;
            m1 = 1-mp1;
         }else{
             mc = r;
@@ -86,8 +90,23 @@
     }
 }
 
-int main() {
-    int8_t nx,ny,x,y,down_val,up_val;
+void slide(int a,int b)
+{
+    if(a == 0)
+    {
+        slidem = 1;
+    }else
+    if(b == 0)
+    {
+        slidem = 2;
+    }else{
+        slidem = 0;
+    }
+}
+
+int main() 
+{
+    int8_t nx,ny,x,y,down_val,up_val,slidel,slider;
     while(1) {
         if (trans.getc()== 255){
             nx =trans.getc();
@@ -96,9 +115,11 @@
             y = trans.getc();
             up_val = trans.getc();
             down_val = trans.getc();
+            slidel = trans.getc();
+            slider = trans.getc();
             move(nx,ny,x,y);
-            up_down(up_val,down_val);                    
+            up_down(up_val,down_val);
+            slide(slidel,slider);                    
         }
-        
     }      
 }