タームAのプログラム

Dependencies:   mbed

Revision:
0:a1535b0b1c12
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 29 07:23:54 2016 +0000
@@ -0,0 +1,92 @@
+//リフト上げ条件センサ2つ
+
+#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 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(in2 == 0 && in3 == 0)
+        {
+            lmotor = 0;
+            vl = 0.0f;
+            rmotor = 1;
+            vr = 0.1f;
+        }
+        else if(in2 == 0 && in3 == 1)
+        {
+            lmotor = 0;
+            vl = 0.0f;
+            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 && in4 == 0)
+        {
+            cmotor = 1;
+            vc = 0.5f;
+            lmotor = 0;
+            vl = 0.0f;
+            rmotor = 0;
+            vr = 0.0f;
+            wait(0.5);
+            cmotor = 0;
+            vc = 0.0f;
+            lmotor = 0;
+            vl = 0.0f;
+            rmotor = 0;
+            vr = 0.0f;
+            wait(10);
+        }
+    }
+}
\ No newline at end of file