diff --git a/examples/Testing_communications/Testing_communications.ino b/examples/Testing_communications/Testing_communications.ino deleted file mode 100644 index 72b4b7b..0000000 --- a/examples/Testing_communications/Testing_communications.ino +++ /dev/null @@ -1,23 +0,0 @@ -#include "Braccio++.h" - -int selected_motor = 0; - -void setup() { - Serial.begin(115200); - while(!Serial){} - Serial.println("Testing the motor communication!"); - Braccio.begin(); -} - -void loop() { - Serial.println("Choose the motor 1 to 6 to test the connection:"); - while((Serial.available() <= 0)){}; - int motorID = Serial.parseInt(); - - bool connected = (Braccio.connected(motorID)); - if (connected) - Serial.println("Communcation with motor " + String(motorID) + " successful"); - else - Serial.println("Communcation failure - Please check the motor " + String(motorID) + " connection"); - Serial.println(); -} diff --git a/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino new file mode 100644 index 0000000..5e7972b --- /dev/null +++ b/examples/Tools/Test_Motor_Communication/Test_Motor_Communication.ino @@ -0,0 +1,37 @@ +/* This example allows a user to test if communication + * can be established with a motor which can be selected + * via inputting the desired number in the serial monitor. + */ + +#include + +void setup() +{ + Serial.begin(115200); + while(!Serial) { } + + Braccio.begin(); + Serial.println("Testing motor communication!"); + Serial.println("Choose motor 1 to 6 to test the connection"); + Serial.print(">> "); +} + +void loop() +{ + while(Serial.available() <= 0) { } + int const motorID = Serial.parseInt(); + while(Serial.read() != '\n') { } + + if (motorID < 1 || motorID > 6) { + Serial.println("Error, wrong motor id, choose value between 1 and 6"); + Serial.print(">> "); + return; + } + + if (Braccio.connected(motorID)) + Serial.println("Communication with motor " + String(motorID) + " successful"); + else + Serial.println("Communication failure - Please check the motor " + String(motorID) + " connection"); + + Serial.print(">> "); +}