PickBeeperToWall
Revision 5:6b667e2cb800, committed 2015-04-10
- Comitter:
- bulmecisco
- Date:
- Fri Apr 10 07:12:07 2015 +0000
- Parent:
- 4:76acfddc26fb
- Child:
- 6:267f417dbce0
- Child:
- 7:df6830254e8b
- Commit message:
- Button test added: IsButtonPressed.
Changed in this revision
ur_Bertl.cpp | Show annotated file Show diff for this revision Revisions of this file |
ur_Bertl.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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() {
--- a/ur_Bertl.h Tue Apr 07 12:30:39 2015 +0000 +++ b/ur_Bertl.h Fri Apr 10 07:12:07 2015 +0000 @@ -152,6 +152,7 @@ bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ bool FrontIsClear(); /**< returns a boolean value true if front is free; if not false */ bool NextToABeeper(); /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ + bool IsButtonPressed(const int btn); int AnyBeeperInBag(); /**< returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false */ void NibbleLeds(int value); /**< methode for the 4 (half byte) yellow LEDs at the back left side; ie. you can show how many beeper a robot has in his bag with: karel.NibbleLeds(karel.AnyBeeperInBag())*/ void TurnLedOn(int16_t led);/**< turns the specified one or more LEDs ON; description and name in const.h, such as LED_FL1 = 0x01; front LED white */