Leds work simultanously. Version 3.1

Dependencies:   HCSR

Dependents:   bertl_led bertl_led bertl_led bertl_led ... more

Fork of Bertl by Bertl_Team_PE

BULME HTL Graz-Gösting

FSST - Hardwarenahe Programmierung

Created by Prof.Dr. Franz Pucher

Inhalt

Inhalt

Start mit folgendem Code in main.cpp eines neuen Projektes mbed_blinky:

#include "mbed.h"
#include "const.h"
#include "Robot.h"

Robot bertl;
    
int main()
{
    bertl.NibbleLeds(0x0F);
    wait(1);
    bertl.NibbleLeds(0x00);
    
    while(1)
    {
        if(bertl.IsButtonPressed(BTN_BL))
        {
            bertl.TurnLedOn(LED_BL1);
        }
        if(bertl.IsButtonPressed(BTN_BR))
        {
            bertl.TurnLedOff(LED_BL1);
        }
    }
}
Revision:
13:3ce84646fd74
Parent:
12:cedc088eaf05
Child:
15:43d6a7e6e64a
--- a/ur_Bertl.cpp	Sun Apr 26 20:04:47 2015 +0000
+++ b/ur_Bertl.cpp	Mon Apr 27 13:13:45 2015 +0000
@@ -1,5 +1,6 @@
 /***********************************
-name:   ur_Bertl.cpp    Version: 2.2
+name:   ur_Bertl.cpp    Version: 3.0
+        class Bertl included
 author: PE HTL BULME
 email:  pe@bulme.at
 WIKI:   https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
@@ -13,7 +14,7 @@
 #include "ur_Bertl.h"
 
 // Constructor
-ur_Bertl::ur_Bertl() : _interrupt(P1_12)            // left sensor P1_13
+ur_Bertl::ur_Bertl() : _interrupt(MOTORENC)         
 {
     i2c.frequency(40000);                           // I2C init
     char init1[2] = {0x6, 0x00};
@@ -374,7 +375,7 @@
 }
 
 // -------------------- BERTL CLASS -------------------------------------
-void Bertl::MoveBackwards(int move)
+int Bertl::MoveBackwards(int move)
 {
     int count = _count;
     //wait_ms(250);                         // waite until Bertl stops
@@ -393,8 +394,35 @@
     MotorR_EN=MotorL_EN=0;
     if(move == MOVE)
         wait_ms(250);
+    return _count - count;
 }
 // ------------------------- BERT CLASS --------------------------------------
+int Bertl::Move(int move)
+{
+    int count = _count;
+    MotorR_EN=MotorL_EN=1;                  // both motor ENABLE
+    MotorR_FORWARD = MotorL_FORWARD = 1;    // both motor forward ON
+#ifdef TIME
+    wait_ms(move);
+#else
+
+    while(_count < count+move) {
+        //if(!FrontIsClear())       // more convenient because there are no accidents :-)
+          //  break;
+#ifdef FRONTBUTTON
+        if(frontButtonPressed())
+            error();
+#endif
+        DEBUG_PRINT("count: %d _count: %d", count, _count);
+    }
+#endif
+    MotorR_FORWARD = MotorL_FORWARD = 0;    // both motor off
+    MotorR_EN=MotorL_EN=0;
+    if(move == MOVE)
+        wait_ms(250);
+    return _count - count;
+}
+
 void Bertl::TurnRigth()
 {
     int count = _count;
@@ -475,4 +503,11 @@
     
     detect = linesensor;
     return detect;
-}
\ No newline at end of file
+}
+
+void Bertl::RGBLed(bool red, bool green, bool blue)
+{
+      RGB_blue=!blue;
+      RGB_red=!red;
+      RGB_green=!green;
+}