-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} 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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
examples/Testing_communications/Testing_communications.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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