Skip to content

chore: add basic examples #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/Check_inputs/Check_inputs.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#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);
}
23 changes: 23 additions & 0 deletions examples/LCD_Custom_Menu/LCD_Custom_Menu.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "Braccio++.h"

#define MARGIN_LEFT 0
#define MARGIN_TOP 0

static const char * btnm_map[] = {"Option 1", "\n",
"Option 2", "\n",
"Option 3", "\n", "\0"
};

void customMenu(){
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
}

void setup() {
Braccio.begin(customMenu);
}

void loop() {

}
43 changes: 43 additions & 0 deletions examples/LCD_Menu_Joystick/LCD_Menu_Joystick.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "Braccio++.h"

#define MARGIN_LEFT 0
#define MARGIN_TOP 0

static void event_handler(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED) {
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);

LV_LOG_USER("%s was pressed\n", txt);
Serial.println(String(txt) + " was pressed.");
}
}

static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 3", "Option 4", "\n",
"Option 5", "Option 6", "\n", "\0"
};

void customMenu(){
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 1, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 2, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 3, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 4, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 5, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
Braccio.connectJoystickTo(btnm1);
}

void setup() {
Braccio.begin(customMenu);
}

void loop() {

}
71 changes: 71 additions & 0 deletions examples/LCD_Motors/LCD_Motors.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "Braccio++.h"

int selected_motor = 0;

static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED) {
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);

LV_LOG_USER("%s was pressed\n", txt);
Serial.println(txt);
if (strcmp(txt, "Motor 1") == 0) {
selected_motor = 1;
Braccio.ping_allowed = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold for the ping_allowed variable (it was my quick and dirty hack to allow some clean operations), but I'd merge the examples anyway and eventually refactor them if I remove that functionality

} else if (strcmp(txt, "Motor 2") == 0) {
selected_motor = 2;
Braccio.ping_allowed = false;
} else if (strcmp(txt, "Motor 3") == 0) {
selected_motor = 3;
Braccio.ping_allowed = false;
} else if (strcmp(txt, "Motor 4") == 0) {
selected_motor = 4;
Braccio.ping_allowed = false;
} else if (strcmp(txt, "Motor 5") == 0) {
selected_motor = 5;
Braccio.ping_allowed = false;
} else if (strcmp(txt, "Motor 6") == 0) {
selected_motor = 6;
Braccio.ping_allowed = false;
} else {
Braccio.ping_allowed = true;
selected_motor = 0;
}
}
}


static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
"Motor 3", "Motor 4", "\n",
"Motor 5", "Motor 6", "\n", "\0"
};

void customMenu() {
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 1, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 2, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 3, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 4, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 5, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
Braccio.connectJoystickTo(btnm1);
}

void setup() {
// Call Braccio.begin() for default menu or pass a function for custom menu
Braccio.begin(customMenu);
Serial.begin(115200);
}

void loop() {
for (float angle = 0.0; angle <= 180.0; angle+=10.0){
Braccio.move(selected_motor).to(angle);
delay(500);
}
}
22 changes: 22 additions & 0 deletions examples/Moving_Motors/Moving_Motors.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "Braccio++.h"

int selected_motor = 0;

void setup() {
// Call Braccio.begin() for default menu or pass a function for custom menu
Braccio.begin();
Serial.begin(115200);
while(!Serial){}
Serial.println("Testing the motor angular moviment!");
}

void loop() {
Serial.println("Choose the motor 1 to 6 to test the connection:");
while((Serial.available() <= 0)){};
int selected_motor = Serial.parseInt();
for (float i = 0.0; i <= 180.0; i+=10.0){
Braccio.move(selected_motor).to(i);
Serial.println("Current angle: " + String(i));
delay(100);
}
}
23 changes: 23 additions & 0 deletions examples/Testing_communications/Testing_communications.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#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();
}