ultra sonic sensor asdded

Dependencies:   HCSR mbed

Fork of func_Bertl by BULME_BERTL14

Revision:
5:7b091d085c70
Parent:
4:a975caedface
Child:
6:be710baf53ec
diff -r a975caedface -r 7b091d085c70 main.cpp
--- a/main.cpp	Sun Jan 11 08:42:08 2015 +0000
+++ b/main.cpp	Thu Jan 15 10:18:16 2015 +0000
@@ -1,15 +1,55 @@
 /***********************************
-* name:   ur_Karel    v 0.2
+* name:   func_Bertl    v 0.2
 * author: PE HTL BULME
 * email:  pe@bulme.at
 * description:
-*    functions for Karel The Robot
+*    functions for Bertl The Robot
 *
 *************************************/
 #include "mbed.h"
 #include "config.h"
 
+void ShutOff();
+void Move();
 bool FrontIsClear();
+bool MoveMeasure(int time, int& left, int& right);
+bool MoveTicks(int ticks);
+void TurnBack();
+void TurnLeftTicks(int ticks);
+void TurnLeftTime(int ms);
+void TurnLeft();
+void TurnLedOn(int16_t led);
+void TurnLedOff(int16_t led);
+void MoveMore(int anzahl);
+void Back();
+bool WaitUntilButtonPressed();
+bool Start();
+
+
+// *************  Hauptprogramm ************
+int main()
+{
+    while(!Start()) {}   // wait to start
+    wait_ms(200);
+
+    Move();   
+    TurnLeft();
+    Move();
+
+    ShutOff();
+    return 0;
+}
+
+
+bool Start()
+{
+    DEBUG_PRINT("Debug level: %d", (int) DEBUG);
+    i2c.frequency(40000);       // I2C Frequenz 40kHz
+
+    while(WaitUntilButtonPressed()) {    }
+    return true;
+}
+
 
 void ShutOff()
 {
@@ -171,6 +211,28 @@
     wait_ms(250);           // only to step the robot
 }
 
+bool WaitUntilButtonPressed()
+{
+    char cmd[3];
+    int16_t btns;
+    bool wert;
+
+    cmd[0] = 0x06;
+    cmd[1] = 0x00;
+    i2c.write(addr, cmd, 2); // Define Port0 = Out
+
+    cmd[0]=0x01;
+    i2c.write(addr, cmd, 1);
+    i2c.read(addr|1, cmd, 1);
+    btns = cmd[0];
+    if( btns & (0xFF))
+        wert = false;
+    else
+        wert = true;
+    DEBUG_PRINT("\right\nWERT: %d \right\n", wert);
+    return wert;
+}
+
 void TurnLedOn(int16_t led)
 {
     char cmd[3];
@@ -191,6 +253,7 @@
     wait(0.5);
 }
 
+/*
 void TurnAllLedOff()
 {
     TurnLedOff(LED_ALL);
@@ -213,37 +276,6 @@
     TurnLeftTicks(150);
 }
 
-bool WaitUntilButtonPressed()
-{
-    char cmd[3];
-    int16_t btns;
-    bool wert;
-
-    cmd[0] = 0x06;
-    cmd[1] = 0x00;
-    i2c.write(addr, cmd, 2); // Define Port0 = Out
-
-    cmd[0]=0x01;
-    i2c.write(addr, cmd, 1);
-    i2c.read(addr|1, cmd, 1);
-    btns = cmd[0];
-    if( btns & (0xFF))
-        wert = false;
-    else
-        wert = true;
-    DEBUG_PRINT("\right\nWERT: %d \right\n", wert);
-    return wert;
-}
-
-bool Start()
-{
-    while(WaitUntilButtonPressed()) {
-        LED_D12 = !LED_D12;
-        wait_ms(250);
-    }
-    return true;
-}
-
 void MoveWhileFrontIsClear()
 {
     while(FrontIsClear()) {
@@ -251,38 +283,12 @@
     }
 }
 
-// *************  Hauptprogramm ************
-int main()
+void LedTest()
 {
-    DEBUG_PRINT("Debug level: %d", (int) DEBUG);
-    i2c.frequency(40000);       // I2C Frequenz 40kHz
-
-    // LED test
-    LED_D12 = 1;
     TurnLedOn(LED_FL1 |LED_FR1);
     wait(1);
     TurnAllLedOn();
     wait(1);
     TurnLedOff(LED_FL1 |LED_FR1);
-
-    while(!Start()) {}   // wait to start
-    wait_ms(200);
-
-    MoveWhileFrontIsClear();
-    
-    TurnAllLedOff();
-    wait(1);
-
-    while(FrontIsClear()) {
-        Move();
-    }
-    Back();
-    wait(1);
-
-    while(FrontIsClear()) {
-        MoveTicks(50);
-    }
-    TurnLedOn(LED_ALL_FRONT);
-    ShutOff();
-    return 0;
 }
+*/
\ No newline at end of file