BingBong

Dependencies:   BertlLib mbed

Fork of BertlTemplate2 by michael hollegha

Revision:
3:57fc35fcd060
Parent:
2:d24a3d2438a4
Child:
4:3aca65c975f0
--- a/BertlTemplate.cpp	Mon Feb 22 10:55:46 2016 +0000
+++ b/BertlTemplate.cpp	Mon May 02 15:49:14 2016 +0000
@@ -7,18 +7,81 @@
 //              main=2^0  LS    ENC 2^2
 BusOut boardPow(p30,      P1_6, P1_7);
 
-int main(void)
+Timer t1,t2;
+
+void BlinkTask_Forward()
+{
+    if(t1.read_ms()>100) {
+        t1.reset();
+        pex.ToggleLeds(LED_ALL_FRONT);}
+        
+}
+void BlinkTask_Backward()
 {
-    boardPow=1; wait_ms(10);
-    InitBertl();
-    pex.useISR=0; leds=9;
+    if(t2.read_ms()>200) {
+        t2.reset();
+        pex.ToggleLeds(LED_ALL_BACK);
+        
+    }
+}
+
+void ForwardUntilWall()
+{
+    mL.SetPow2(0.3);
+    mR.SetPow2(0.3); //Leistung 30% .. 0.3
+    
+    
+    while(1) {
+        pex.ReadButtons();
+        if (pex.IsButton (BTN_FM))
+            break;
+        BlinkTask_Forward();
+    }
+    mL.SetPow2(0.0);
+    mR.SetPow2(0.0);
     pex.ClearLeds();
+}
+
+void BackwardUntilWall()
+{
     
-    while(1)
-    {
+    mL.SetPow2(-0.3);
+    mR.SetPow2(-0.3); //Leistung 30% .. 0.3
+   
+    
+    while(1) {
+        pex.ReadButtons();
+        if (pex.IsButton (BTN_BM))
+            break;
+            BlinkTask_Backward();
     }
-    
-    return 1;
+    mL.SetPow2(0.0);
+    mR.SetPow2(0.0);
+    pex.ClearLeds();
 }
 
 
+int main(void)
+{
+    boardPow=1;
+    wait_ms(10);
+    InitBertl();
+    pex.useISR=0;
+    leds=0;
+    pex.ClearLeds();
+
+    pex.WaitUntilFrontButtonPressed();
+    t1.start();
+    t2.start();
+
+    while(1) {
+
+        ForwardUntilWall();
+        BackwardUntilWall();
+
+    }
+    return 1;
+
+}
+
+