Skip to content

Add simplified joystick API #22

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 3 commits into from
Jan 13, 2022
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
42 changes: 0 additions & 42 deletions examples/Tools/Check_Inputs/Check_Inputs.ino

This file was deleted.

27 changes: 27 additions & 0 deletions examples/Tools/Test_Inputs/Test_Inputs.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* This example allows the user to read the
* inputs of the Braccio++ shield UI devices:
* - joystick (up,down,left,right,select)
* - button (enter)
*/

#include <Braccio++.h>

void setup()
{
Serial.begin(115200);
while(!Serial){}

Braccio.begin();
Serial.println("Press any button or move the joystick.");
}

void loop()
{
if(Braccio.isJoystickPressed_LEFT()) Serial.println("LEFT (Joystick)");
if(Braccio.isJoystickPressed_RIGHT()) Serial.println("RIGHT (Joystick)");
if(Braccio.isJoystickPressed_SELECT())Serial.println("SELECT (Joystick)");
if(Braccio.isJoystickPressed_UP()) Serial.println("UP (Joystick)");
if(Braccio.isJoystickPressed_DOWN()) Serial.println("DOWN (Joystick)");
if(Braccio.isButtonPressed_ENTER()) Serial.println("ENTER (Button)");
delay(100);
}
12 changes: 6 additions & 6 deletions src/Braccio++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,22 @@ void BraccioClass::motors_connected_thread() {
}

int BraccioClass::getKey() {
if (digitalRead(BTN_LEFT) == LOW) {
if (isJoystickPressed_LEFT()) {
return 1;
}
if (digitalRead(BTN_RIGHT) == LOW) {
if (isJoystickPressed_RIGHT()) {
return 2;
}
if (digitalRead(BTN_SEL) == LOW) {
if (isJoystickPressed_SELECT()) {
return 3;
}
if (digitalRead(BTN_UP) == LOW) {
if (isJoystickPressed_UP()) {
return 4;
}
if (digitalRead(BTN_DOWN) == LOW) {
if (isJoystickPressed_DOWN()) {
return 5;
}
if (digitalRead(BTN_ENTER) == LOW) {
if (isButtonPressed_ENTER()) {
return 6;
}
return 0;
Expand Down
7 changes: 7 additions & 0 deletions src/Braccio++.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ class BraccioClass
int getKey();
void connectJoystickTo(lv_obj_t* obj);

inline bool isJoystickPressed_LEFT() { return (digitalRead(BTN_LEFT) == LOW); }
inline bool isJoystickPressed_RIGHT() { return (digitalRead(BTN_RIGHT) == LOW); }
inline bool isJoystickPressed_SELECT() { return (digitalRead(BTN_SEL) == LOW); }
inline bool isJoystickPressed_UP() { return (digitalRead(BTN_UP) == LOW); }
inline bool isJoystickPressed_DOWN() { return (digitalRead(BTN_DOWN) == LOW); }
inline bool isButtonPressed_ENTER() { return (digitalRead(BTN_ENTER) == LOW); }

TFT_eSPI gfx = TFT_eSPI();

bool ping_allowed = true;
Expand Down