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:
5:6b667e2cb800
Parent:
4:76acfddc26fb
Child:
6:df6830254e8b
--- a/ur_Bertl.cpp	Tue Apr 07 12:30:39 2015 +0000
+++ b/ur_Bertl.cpp	Fri Apr 10 07:12:07 2015 +0000
@@ -260,6 +260,28 @@
     wait_ms(250);
 }
 
+bool ur_Bertl::IsButtonPressed(const int btn)
+{
+    char cmd[3];            // array for I2C
+    int16_t btns;
+    bool wert;
+
+    cmd[0] = 0x06;
+    cmd[1] = 0x00;
+    i2c.write(addr, cmd, 2); 
+
+    cmd[0]=0x01;
+    i2c.write(addr, cmd, 1);
+    i2c.read(addr|1, cmd, 1);
+    btns = cmd[0];
+    if( btns & btn)
+        wert = true;
+    else
+        wert = false;
+    DEBUG_PRINT("WERT: %d", wert);
+    return wert;
+}
+
 // Protected methodes
 
 int ur_Bertl::bottomIsBlack()
@@ -314,6 +336,8 @@
     return wert;
 }
 
+
+
 //-----------------INTERNAL USE ONLY ----------------------------
 void ur_Bertl::error()
 {