今入ってるやつです。

Dependencies:   mbed

Revision:
0:e9aeba51adef
diff -r 000000000000 -r e9aeba51adef main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 29 07:34:34 2016 +0000
@@ -0,0 +1,203 @@
+#include "mbed.h"
+
+BusOut l1(PTB11);
+BusOut l2(PTB10);
+BusOut l3(PTB9);
+BusOut l4(PTB8);
+
+AnalogIn sensor1(PTB1);
+AnalogIn sensor2(PTB3);
+AnalogIn sensor3(PTB2);
+AnalogIn sensor4(PTB0);
+
+BusOut i1(PTA1,PTA2);
+PwmOut p1(PTD4);
+BusOut i2(PTC0,PTC7);
+PwmOut p2(PTA12);
+BusOut i3(PTC5,PTC6);
+PwmOut p3(PTA4);
+
+int main(){
+float analog1,analog2,analog3,analog4;   
+int count=0; 
+    while(1){
+        analog1 = sensor1.read();
+        analog2 = sensor2.read();
+        analog3 = sensor3.read();
+        analog4 = sensor4.read();
+/*dousakakunin*/
+        if(analog1 > 0.2){
+                l1 = 1;
+            }
+        if(analog1 < 0.2){
+                l1=0;
+            }
+        if(analog2 > 0.2){
+                    l2=1;
+            }
+        if(analog2 < 0.2){
+                    l2=0;
+            }
+        if(analog3 > 0.2){
+                    l3=1;
+            }
+        if(analog3 < 0.2){
+                    l3=0;
+            }
+        if(analog4 > 0.2){
+                    l4=1;
+            }
+        if(analog4 < 0.2){
+                    l4=0;
+            }
+ if(count == 0)   {        
+/*usetu dai*/            
+        if(analog1 > 0.2 && analog2 > 0.2 && analog3 < 0.2){
+                i1=1;
+                i2=0;
+                p1=0.0045f;
+                p2=0.0f;
+                
+            }
+/*center*/            
+        else if(analog1 > 0.2 && analog2 < 0.2 && analog3 > 0.2 && analog4 > 0.2){
+                i1=1;
+                i2=1;
+                p1=0.0055f;
+                p2=0.0055f;
+               
+            }
+/*sasetu dai*/            
+        else if(analog1 < 0.2 && analog2 > 0.2 && analog3 > 0.2 ){
+                    i1=0;
+                    i2=1;
+                    p1=0.0f;
+                    p2=0.0045f;
+            }
+/*usetu syou*/            
+        else if(analog1 < 0.2 && analog2 < 0.2 && analog3 > 0.2){
+                    i1=1;
+                    i2=1;
+                    p1=0.0045f;
+                    p2=0.0055f;
+                 
+            }
+/* sasetu syou*/          
+         else if(analog1 > 0.2 && analog2 < 0.2 && analog3 < 0.2){
+                    i1=1;
+                    i2=1;
+                    p1=0.0055f;
+                    p2=0.0045f;
+            }
+/*lift up */     
+        else if(analog1 > 0.2 && analog2 < 0.2 && analog3 > 0.2 && analog4 < 0.2){     
+                    if(count==0){
+                    i1=1;
+                    i2=1;
+                    i3=1;
+                    p1=0.0f;
+                    p2=0.0f;
+                    p3=1.0f;
+                    wait(3.5);
+                    i3=0;
+                    i1=1;
+                    i2=1;
+                    p1=0.2f;
+                    p2=0.2f;
+                    p3=0.0f;
+                    wait(1.0);
+                    count++;
+                 }
+                    
+            }
+        else if(analog1 < 0.2 && analog2 < 0.2 && analog3 < 0.2){
+                    p1=0.005f;
+                    p2=0.005f;
+            }
+        else{
+            i1=1;
+            i2=1;
+            p1=0.0045f;
+            p2=0.0f;
+            }
+    }
+
+
+else if(count == 1){
+      /*usetu dai*/            
+        if(analog1 > 0.2 && analog2 > 0.2 && analog3 < 0.2){
+                i1=1;
+                i2=0;
+                p1=0.006f;
+                p2=0.0f;
+                
+            }
+/*center*/            
+        else if(analog1 > 0.2 && analog2 < 0.2 && analog3 > 0.2 && analog4 > 0.2){
+                i1=1;
+                i2=1;
+                p1=0.006f;
+                p2=0.006f;
+               
+            }
+/*sasetu dai*/            
+        else if(analog1 < 0.2 && analog2 > 0.2 && analog3 > 0.2 ){
+                    i1=0;
+                    i2=1;
+                    p1=0.0f;
+                    p2=0.006f;
+            }
+/*usetu syou*/            
+        else if(analog1 < 0.2 && analog2 < 0.2 && analog3 > 0.2){
+                    i1=1;
+                    i2=1;
+                    p1=0.006f;
+                    p2=0.008f;
+                 
+            }
+/* sasetu syou*/          
+         else if(analog1 > 0.2 && analog2 < 0.2 && analog3 < 0.2){
+                    i1=1;
+                    i2=1;
+                    p1=0.008f;
+                    p2=0.006f;
+            }
+        /* lift down*/           
+        else if(analog1 > 0.2 && analog2 < 0.2 && analog3 > 0.2 && analog4 < 0.2){
+                    if(count==1){
+                    i1=1;
+                    i2=1;
+                    i3=2;
+                    p1=0.0f;
+                    p2=0.0f;
+                    p3=1.0f;
+                    wait(3.0);
+                    i1=2;
+                    i2=2;
+                    i3=1;
+                    p3=0.0f;
+                    p1=1.0f;
+                    p2=1.0f;
+                    wait(1.5);
+                    i1=1;
+                    i2=1;
+                    p1=0.0f;
+                    p2=0.0f;
+                    count=0;
+                }
+                    
+            }
+        else if(analog1 < 0.2 && analog2 < 0.2 && analog3 < 0.2){
+                    p1=0.005f;
+                    p2=0.005f;
+            }
+        else{
+            i1=1;
+            i2=1;
+            p1=0.0045f;
+            p2=0.0f;
+            }
+        }  
+       
+    }
+}