diff --git a/examples/Tools/Check_Inputs/Check_Inputs.ino b/examples/Tools/Check_Inputs/Check_Inputs.ino deleted file mode 100644 index 27b42d8..0000000 --- a/examples/Tools/Check_Inputs/Check_Inputs.ino +++ /dev/null @@ -1,42 +0,0 @@ -/* This example allows the user to read the - * inputs of the Braccio++ shield UI devices: - * - joystick (up,down,left,right,select) - * - button (enter) - */ - -#include - -String toMessage(int const input) -{ - static String const message[] = - { "", - "LEFT (Joystick)", - "RIGHT (Joystick)", - "SELECT (Joystick)", - "UP (Joystick)", - "DOWN (Joystick)", - "ENTER (Button)" - }; - - if (input < 7) - return message[input]; - else - return String("Error, invalid input value"); -} - -void setup() -{ - Serial.begin(115200); - while(!Serial){} - - Braccio.begin(); - Serial.println("Press any button or move the joystick."); -} - -void loop() -{ - String const message = toMessage(Braccio.getKey()); - if(message != "") - Serial.println(message); - delay(100); -} diff --git a/examples/Tools/Test_Inputs/Test_Inputs.ino b/examples/Tools/Test_Inputs/Test_Inputs.ino new file mode 100644 index 0000000..9d2020f --- /dev/null +++ b/examples/Tools/Test_Inputs/Test_Inputs.ino @@ -0,0 +1,27 @@ +/* This example allows the user to read the + * inputs of the Braccio++ shield UI devices: + * - joystick (up,down,left,right,select) + * - button (enter) + */ + +#include + +void setup() +{ + Serial.begin(115200); + while(!Serial){} + + Braccio.begin(); + Serial.println("Press any button or move the joystick."); +} + +void loop() +{ + if(Braccio.isJoystickPressed_LEFT()) Serial.println("LEFT (Joystick)"); + if(Braccio.isJoystickPressed_RIGHT()) Serial.println("RIGHT (Joystick)"); + if(Braccio.isJoystickPressed_SELECT())Serial.println("SELECT (Joystick)"); + if(Braccio.isJoystickPressed_UP()) Serial.println("UP (Joystick)"); + if(Braccio.isJoystickPressed_DOWN()) Serial.println("DOWN (Joystick)"); + if(Braccio.isButtonPressed_ENTER()) Serial.println("ENTER (Button)"); + delay(100); +} diff --git a/src/Braccio++.cpp b/src/Braccio++.cpp index c88d920..450c8d2 100644 --- a/src/Braccio++.cpp +++ b/src/Braccio++.cpp @@ -272,22 +272,22 @@ void BraccioClass::motors_connected_thread() { } int BraccioClass::getKey() { - if (digitalRead(BTN_LEFT) == LOW) { + if (isJoystickPressed_LEFT()) { return 1; } - if (digitalRead(BTN_RIGHT) == LOW) { + if (isJoystickPressed_RIGHT()) { return 2; } - if (digitalRead(BTN_SEL) == LOW) { + if (isJoystickPressed_SELECT()) { return 3; } - if (digitalRead(BTN_UP) == LOW) { + if (isJoystickPressed_UP()) { return 4; } - if (digitalRead(BTN_DOWN) == LOW) { + if (isJoystickPressed_DOWN()) { return 5; } - if (digitalRead(BTN_ENTER) == LOW) { + if (isButtonPressed_ENTER()) { return 6; } return 0; diff --git a/src/Braccio++.h b/src/Braccio++.h index 2cc01a8..8496201 100644 --- a/src/Braccio++.h +++ b/src/Braccio++.h @@ -146,6 +146,13 @@ class BraccioClass int getKey(); void connectJoystickTo(lv_obj_t* obj); + inline bool isJoystickPressed_LEFT() { return (digitalRead(BTN_LEFT) == LOW); } + inline bool isJoystickPressed_RIGHT() { return (digitalRead(BTN_RIGHT) == LOW); } + inline bool isJoystickPressed_SELECT() { return (digitalRead(BTN_SEL) == LOW); } + inline bool isJoystickPressed_UP() { return (digitalRead(BTN_UP) == LOW); } + inline bool isJoystickPressed_DOWN() { return (digitalRead(BTN_DOWN) == LOW); } + inline bool isButtonPressed_ENTER() { return (digitalRead(BTN_ENTER) == LOW); } + TFT_eSPI gfx = TFT_eSPI(); bool ping_allowed = true;