Skip to content

Commit d647b9c

Browse files
authored
Merge pull request #10 from bcmi-labs/fix-serial-test-example
Clean-up and refactor `examples`/`Test_communications`
2 parents cfda43e + 3767210 commit d647b9c

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

examples/Testing_communications/Testing_communications.ino

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* This example allows a user to test if communication
2+
* can be established with a motor which can be selected
3+
* via inputting the desired number in the serial monitor.
4+
*/
5+
6+
#include <Braccio++.h>
7+
8+
void setup()
9+
{
10+
Serial.begin(115200);
11+
while(!Serial) { }
12+
13+
Braccio.begin();
14+
Serial.println("Testing motor communication!");
15+
Serial.println("Choose motor 1 to 6 to test the connection");
16+
Serial.print(">> ");
17+
}
18+
19+
void loop()
20+
{
21+
while(Serial.available() <= 0) { }
22+
int const motorID = Serial.parseInt();
23+
while(Serial.read() != '\n') { }
24+
25+
if (motorID < 1 || motorID > 6) {
26+
Serial.println("Error, wrong motor id, choose value between 1 and 6");
27+
Serial.print(">> ");
28+
return;
29+
}
30+
31+
if (Braccio.connected(motorID))
32+
Serial.println("Communication with motor " + String(motorID) + " successful");
33+
else
34+
Serial.println("Communication failure - Please check the motor " + String(motorID) + " connection");
35+
36+
Serial.print(">> ");
37+
}

0 commit comments

Comments
 (0)