robot / Mbed 2 deprecated DriveXchange_team

Dependencies:   mbed

Revision:
0:2e4509e0eb06
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2motor-2sensor-hbrug.cpp	Fri May 29 07:38:47 2020 +0000
@@ -0,0 +1,100 @@
+#include "mbed.h"
+DigitalOut links1(PB_4);
+DigitalOut rechts1(PB_5);
+DigitalOut links2(PF_0);
+DigitalOut rechts2(PF_1);
+PwmOut pwm1(PA_8);
+PwmOut pwm2(PB_1);
+InterruptIn sensor1(PA_10, PullDown);
+InterruptIn sensor2(PA_9, PullDown);
+Serial pc(USBTX, USBRX);
+
+Timer timer;
+
+int a = 0;
+int b = 0;
+int c = 0;
+int d = 0;
+    
+    
+void rechtdoor(){
+    a = 1; 
+    }
+void achteruit(){
+    b = 1;
+    }
+void linksom(){
+    c = 1;
+    }
+void rechtsom(){
+    d = 1;
+    }
+    
+    int main(){
+    
+    int begin;
+    timer.start();
+    begin = timer.read_ms();
+    a = 1;
+        
+    sensor2.rise(linksom);
+    sensor1.rise(rechtsom);
+
+while(1) {
+        
+    if (c == 1 && d == 1){
+        c = 0;
+        d = 0;
+        b = 1;
+        if(timer.read_ms() - begin>2000){
+        a = 1;
+        begin = timer.read_ms();
+        }
+        }
+            else if (c == 1){
+            links1 = 0;
+            rechts1 = 0;
+            links2 = 0;
+            rechts2 = 1;
+            if(timer.read_ms() - begin>2000){
+            c = 0;
+            a = 1;
+            begin = timer.read_ms();
+            }
+            }
+            else if (d == 1){
+            links1 = 1;
+            rechts1 = 0;
+            links2 = 0;
+            rechts2 = 0;
+            if(timer.read_ms() - begin>2000){
+            d = 0;
+            a = 1;
+            begin = timer.read_ms();
+            }
+            }
+        
+    if (a == 1){
+        links1 = 1;
+        rechts1 = 0;
+        links2 = 0;
+        rechts2 = 1;
+        }
+    if (b == 1){
+        links1 = 0;
+        rechts1 = 1;
+        links2 = 1;
+        rechts2 = 0;
+        if(timer.read_ms() - begin>2000){
+        b = 0;
+        a = 1;
+        begin = timer.read_ms();
+        }
+        }
+
+        
+    pwm1 = 0.5;
+    pwm2 = 0.5; 
+          
+   }
+   }
\ No newline at end of file