タームB、ファイナルのプログラム

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
12f2025e
Date:
Thu Sep 29 07:25:38 2016 +0000
Commit message:
???B????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 29 07:25:38 2016 +0000
@@ -0,0 +1,283 @@
+#include "mbed.h"
+
+DigitalIn in1(PTE21);//左
+DigitalIn in2(PTE20);//左中
+DigitalIn in3(PTE23);//右中
+DigitalIn in4(PTE22);//右
+
+DigitalOut led1(PTB8);//左
+DigitalOut led2(PTB9);//左中
+DigitalOut led3(PTB10);//右中
+DigitalOut led4(PTB11);//右
+
+BusOut cmotor(PTA1,PTA2);
+PwmOut vc(PTD4);
+BusOut lmotor(PTC0,PTC7);
+PwmOut vl(PTA12);
+BusOut rmotor(PTC6,PTC5);
+PwmOut vr(PTA4);
+int lift_count = 0;
+
+int main() {
+    while(1) {
+        if(in1 == 1)//黒の時光る 1:白 0:黒
+        led1 = 0;//1:光る 0:光らない
+        else
+        led1 = 1;
+        
+        if(in2 == 1)
+        led2 = 0;
+        else
+        led2 = 1;
+        
+        if(in3 == 1)
+        led3 = 0;
+        else
+        led3 = 1;
+        
+        if(in4 == 1)
+        led4 = 0;
+        else
+        led4 = 1;
+        
+        if(in1 == 0 && in2 == 0)
+        {
+            while(in4 == 1)
+            {
+                if(in1 == 1)//黒の時光る 1:白 0:黒
+                led1 = 0;//1:光る 0:光らない
+                else
+                led1 = 1;
+        
+                if(in2 == 1)
+                led2 = 0;
+                else
+                led2 = 1;
+        
+                if(in3 == 1)
+                led3 = 0;
+                else
+                led3 = 1;
+        
+                if(in4 == 1)
+                led4 = 0;
+                else
+                led4 = 1;
+                
+                lmotor = 1;
+                vl = 0.0f;
+                rmotor = 1;
+                vr = 0.1f;
+                if(in1 == 0 && in2 == 1 && in3 == 0 && in4 == 0)
+                {
+                    if(lift_count == 0)
+                    {
+                        cmotor = 1;
+                        vc = 0.5f;
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(0.5);
+                        cmotor = 1;
+                        vc = 0.0f;
+                        lmotor = 1;
+                        vl = 0.1f;
+                        rmotor = 1;
+                        vr = 0.1f;
+                        wait(1.0);
+                        lift_count = 1;
+                        break;
+                    }
+                    else
+                    {
+                        cmotor = 2;
+                        vc = 0.5f;
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(0.5);
+                        cmotor = 1;
+                        vc = 0.0f;
+                        lmotor = 2;
+                        vl = 1.0f;
+                        rmotor = 2;
+                        vr = 1.0f;
+                        wait(2);
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(5);
+                        lift_count = 0;
+                        break;
+                    }
+                }
+            }
+            lmotor = 1;
+            vl = 0.4f;
+            rmotor = 1;
+            vr = 0.0f;
+            wait(1);
+        }
+        
+/*        if(in3 == 0 && in4 == 0)
+        {
+            while(in1 == 1)
+            {
+                if(in1 == 1)//黒の時光る 1:白 0:黒
+                led1 = 0;//1:光る 0:光らない
+                else
+                led1 = 1;
+        
+                if(in2 == 1)
+                led2 = 0;
+                else
+                led2 = 1;
+        
+                if(in3 == 1)
+                led3 = 0;
+                else
+                led3 = 1;
+        
+                if(in4 == 1)
+                led4 = 0;
+                else
+                led4 = 1;
+
+                lmotor = 1;
+                vl = 0.1f;
+                rmotor = 1;
+                vr = 0.0f;
+                if(in1 == 0 && in2 == 1 && in3 == 0 && in4 == 0)
+                {
+                    if(lift_count == 0)
+                    {
+                        cmotor = 1;
+                        vc = 0.5f;
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(0.5);
+                        cmotor = 1;
+                        vc = 0.0f;
+                        lmotor = 1;
+                        vl = 0.1f;
+                        rmotor = 1;
+                        vr = 0.1f;
+                        wait(1.0);
+                        lift_count = 1;
+                        break;
+                    }
+                    else
+                    {
+                        cmotor = 2;
+                        vc = 0.5f;
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(0.5);
+                        cmotor = 1;
+                        vc = 0.0f;
+                        lmotor = 2;
+                        vl = 1.0f;
+                        rmotor = 2;
+                        vr = 1.0f;
+                        wait(2);
+                        lmotor = 1;
+                        vl = 0.0f;
+                        rmotor = 1;
+                        vr = 0.0f;
+                        wait(5);
+                        lift_count = 0;
+                        break;
+                    }
+                }
+            }
+            lmotor = 1;
+            vl = 0.0f;
+            rmotor = 1;
+            vr = 0.4f;
+            wait(1);
+        }
+*/
+        ///////////////////////         
+        if(in2 == 0 && in3 == 0)
+        {
+            lmotor = 0;
+            vl = 0.0f;
+            rmotor = 1;
+            vr = 0.1f;
+        }
+        else if(in2 == 0 && in3 == 1)
+        {
+            lmotor = 2;
+            vl = 0.1f;
+            rmotor = 1;
+            vr = 0.1f;
+        }
+        else if(in2 == 1 && in3 == 0)
+        {
+            lmotor = 1;
+            vl = 0.1f;
+            rmotor = 1;
+            vr = 0.1f;
+        }
+        else
+        {
+            lmotor = 1;
+            vl = 0.1f;
+            rmotor = 0;
+            vr = 0.0f;
+        }
+        
+        if(in1 == 0 && in2 == 1 && in3 == 0 && in4 == 0)
+        {
+            if(lift_count == 0)
+            {
+                cmotor = 1;
+                vc = 0.5f;
+                lmotor = 1;
+                vl = 0.0f;
+                rmotor = 1;
+                vr = 0.0f;
+                wait(0.5);
+                cmotor = 1;
+                vc = 0.0f;
+                lmotor = 1;
+                vl = 0.1f;
+                rmotor = 1;
+                vr = 0.1f;
+                wait(1.0);
+                lift_count = 1;
+            }
+            else
+            {
+                cmotor = 2;
+                vc = 0.5f;
+                lmotor = 1;
+                vl = 0.0f;
+                rmotor = 1;
+                vr = 0.0f;
+                wait(0.5);
+                cmotor = 1;
+                vc = 0.0f;
+                lmotor = 2;
+                vl = 1.0f;
+                rmotor = 2;
+                vr = 1.0f;
+                wait(2);
+                lmotor = 1;
+                vl = 0.0f;
+                rmotor = 1;
+                vr = 0.0f;
+                wait(5);
+                lift_count = 0;
+            }
+        }
+        
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 29 07:25:38 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85
\ No newline at end of file