Skip to content

Commit a40974b

Browse files
authored
Merge pull request #2 from bcmi-labs/Esquirio/Braccio_v2_library
chore: add basic examples
2 parents 43019c8 + 6528e6d commit a40974b

File tree

6 files changed

+212
-0
lines changed

6 files changed

+212
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "Braccio++.h"
2+
3+
String message = "";
4+
5+
String checkInputs(int input){
6+
String check[] = { "",
7+
"Joystick left was moved!",
8+
"Joystick right was moved!",
9+
"Joystick select button was pressed!",
10+
"Joystick up was moved!",
11+
"Joystick down was moved!",
12+
"Enter button was pressed!"};
13+
return check[input];
14+
}
15+
16+
void setup() {
17+
Serial.begin(115200);
18+
while(!Serial){}
19+
Braccio.begin();
20+
Serial.println("Press any button or move the joystick.");
21+
}
22+
23+
void loop() {
24+
message = checkInputs(Braccio.getKey());
25+
if(message != ""){
26+
Serial.println(message);
27+
message = "";
28+
}
29+
delay(500);
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "Braccio++.h"
2+
3+
#define MARGIN_LEFT 0
4+
#define MARGIN_TOP 0
5+
6+
static const char * btnm_map[] = {"Option 1", "\n",
7+
"Option 2", "\n",
8+
"Option 3", "\n", "\0"
9+
};
10+
11+
void customMenu(){
12+
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
13+
lv_btnmatrix_set_map(btnm1, btnm_map);
14+
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
15+
}
16+
17+
void setup() {
18+
Braccio.begin(customMenu);
19+
}
20+
21+
void loop() {
22+
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "Braccio++.h"
2+
3+
#define MARGIN_LEFT 0
4+
#define MARGIN_TOP 0
5+
6+
static void event_handler(lv_event_t * e){
7+
lv_event_code_t code = lv_event_get_code(e);
8+
lv_obj_t * obj = lv_event_get_target(e);
9+
if (code == LV_EVENT_CLICKED) {
10+
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
11+
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
12+
13+
LV_LOG_USER("%s was pressed\n", txt);
14+
Serial.println(String(txt) + " was pressed.");
15+
}
16+
}
17+
18+
static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
19+
"Option 3", "Option 4", "\n",
20+
"Option 5", "Option 6", "\n", "\0"
21+
};
22+
23+
void customMenu(){
24+
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
25+
lv_btnmatrix_set_map(btnm1, btnm_map);
26+
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
27+
lv_btnmatrix_set_btn_ctrl(btnm1, 1, LV_BTNMATRIX_CTRL_CHECKABLE);
28+
lv_btnmatrix_set_btn_ctrl(btnm1, 2, LV_BTNMATRIX_CTRL_CHECKABLE);
29+
lv_btnmatrix_set_btn_ctrl(btnm1, 3, LV_BTNMATRIX_CTRL_CHECKABLE);
30+
lv_btnmatrix_set_btn_ctrl(btnm1, 4, LV_BTNMATRIX_CTRL_CHECKABLE);
31+
lv_btnmatrix_set_btn_ctrl(btnm1, 5, LV_BTNMATRIX_CTRL_CHECKABLE);
32+
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
33+
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
34+
Braccio.connectJoystickTo(btnm1);
35+
}
36+
37+
void setup() {
38+
Braccio.begin(customMenu);
39+
}
40+
41+
void loop() {
42+
43+
}

examples/LCD_Motors/LCD_Motors.ino

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "Braccio++.h"
2+
3+
int selected_motor = 0;
4+
5+
static void event_handler(lv_event_t * e)
6+
{
7+
lv_event_code_t code = lv_event_get_code(e);
8+
lv_obj_t * obj = lv_event_get_target(e);
9+
if (code == LV_EVENT_CLICKED) {
10+
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
11+
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
12+
13+
LV_LOG_USER("%s was pressed\n", txt);
14+
Serial.println(txt);
15+
if (strcmp(txt, "Motor 1") == 0) {
16+
selected_motor = 1;
17+
Braccio.ping_allowed = false;
18+
} else if (strcmp(txt, "Motor 2") == 0) {
19+
selected_motor = 2;
20+
Braccio.ping_allowed = false;
21+
} else if (strcmp(txt, "Motor 3") == 0) {
22+
selected_motor = 3;
23+
Braccio.ping_allowed = false;
24+
} else if (strcmp(txt, "Motor 4") == 0) {
25+
selected_motor = 4;
26+
Braccio.ping_allowed = false;
27+
} else if (strcmp(txt, "Motor 5") == 0) {
28+
selected_motor = 5;
29+
Braccio.ping_allowed = false;
30+
} else if (strcmp(txt, "Motor 6") == 0) {
31+
selected_motor = 6;
32+
Braccio.ping_allowed = false;
33+
} else {
34+
Braccio.ping_allowed = true;
35+
selected_motor = 0;
36+
}
37+
}
38+
}
39+
40+
41+
static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
42+
"Motor 3", "Motor 4", "\n",
43+
"Motor 5", "Motor 6", "\n", "\0"
44+
};
45+
46+
void customMenu() {
47+
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
48+
lv_btnmatrix_set_map(btnm1, btnm_map);
49+
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
50+
lv_btnmatrix_set_btn_ctrl(btnm1, 1, LV_BTNMATRIX_CTRL_CHECKABLE);
51+
lv_btnmatrix_set_btn_ctrl(btnm1, 2, LV_BTNMATRIX_CTRL_CHECKABLE);
52+
lv_btnmatrix_set_btn_ctrl(btnm1, 3, LV_BTNMATRIX_CTRL_CHECKABLE);
53+
lv_btnmatrix_set_btn_ctrl(btnm1, 4, LV_BTNMATRIX_CTRL_CHECKABLE);
54+
lv_btnmatrix_set_btn_ctrl(btnm1, 5, LV_BTNMATRIX_CTRL_CHECKABLE);
55+
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
56+
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
57+
Braccio.connectJoystickTo(btnm1);
58+
}
59+
60+
void setup() {
61+
// Call Braccio.begin() for default menu or pass a function for custom menu
62+
Braccio.begin(customMenu);
63+
Serial.begin(115200);
64+
}
65+
66+
void loop() {
67+
for (float angle = 0.0; angle <= 180.0; angle+=10.0){
68+
Braccio.move(selected_motor).to(angle);
69+
delay(500);
70+
}
71+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "Braccio++.h"
2+
3+
int selected_motor = 0;
4+
5+
void setup() {
6+
// Call Braccio.begin() for default menu or pass a function for custom menu
7+
Braccio.begin();
8+
Serial.begin(115200);
9+
while(!Serial){}
10+
Serial.println("Testing the motor angular moviment!");
11+
}
12+
13+
void loop() {
14+
Serial.println("Choose the motor 1 to 6 to test the connection:");
15+
while((Serial.available() <= 0)){};
16+
int selected_motor = Serial.parseInt();
17+
for (float i = 0.0; i <= 180.0; i+=10.0){
18+
Braccio.move(selected_motor).to(i);
19+
Serial.println("Current angle: " + String(i));
20+
delay(100);
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "Braccio++.h"
2+
3+
int selected_motor = 0;
4+
5+
void setup() {
6+
Serial.begin(115200);
7+
while(!Serial){}
8+
Serial.println("Testing the motor communication!");
9+
Braccio.begin();
10+
}
11+
12+
void loop() {
13+
Serial.println("Choose the motor 1 to 6 to test the connection:");
14+
while((Serial.available() <= 0)){};
15+
int motorID = Serial.parseInt();
16+
17+
bool connected = (Braccio.connected(motorID));
18+
if (connected)
19+
Serial.println("Communcation with motor " + String(motorID) + " successful");
20+
else
21+
Serial.println("Communcation failure - Please check the motor " + String(motorID) + " connection");
22+
Serial.println();
23+
}

0 commit comments

Comments
 (0)