diff --git a/examples/Check_inputs/Check_inputs.ino b/examples/Check_inputs/Check_inputs.ino deleted file mode 100644 index 5ea9361..0000000 --- a/examples/Check_inputs/Check_inputs.ino +++ /dev/null @@ -1,30 +0,0 @@ -#include "Braccio++.h" - -String message = ""; - -String checkInputs(int input){ - String check[] = { "", - "Joystick left was moved!", - "Joystick right was moved!", - "Joystick select button was pressed!", - "Joystick up was moved!", - "Joystick down was moved!", - "Enter button was pressed!"}; - return check[input]; -} - -void setup() { - Serial.begin(115200); - while(!Serial){} - Braccio.begin(); - Serial.println("Press any button or move the joystick."); -} - -void loop() { - message = checkInputs(Braccio.getKey()); - if(message != ""){ - Serial.println(message); - message = ""; - } - delay(500); -} diff --git a/examples/Tools/Check_Inputs/Check_Inputs.ino b/examples/Tools/Check_Inputs/Check_Inputs.ino new file mode 100644 index 0000000..27b42d8 --- /dev/null +++ b/examples/Tools/Check_Inputs/Check_Inputs.ino @@ -0,0 +1,42 @@ +/* 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); +}