Discord: GAMELASTER#8007
gamelaster / arduinogamepad Goto Github PK
View Code? Open in Web Editor NEWA GamePad HID library for Arduino Pro Micro/Leonardo (ATMega32u4)
A GamePad HID library for Arduino Pro Micro/Leonardo (ATMega32u4)
Probably a minor thing, but I'm only weeks into Arduino use and the current way to install libraries seems to be to use the library manager to install the ZIP directly.
This works fine although I really wish they still supported the "copy and paste" version as that would make it easier to develop and debug, I suspect.
Anyway, I got it loaded so I can give it a go now. Why does USB have to be such a right royal pain the in butt?!
I'm working on a handheld using the pro micro and I need at least two more buttons.
Hello everyone!
I'm in need of some assistance with a custom Arduino Leonardo game controller I've been working on. I've utilized the library here to set up my controller. It's functioning perfectly when tested on the Windows gamepad settings—every button press and joystick movement is detected without any hiccups.
However, I've hit a snag with Recalbox on my Raspberry Pi 4B. While the system does recognize the controller as a Leonardo and allows me to use the joystick to navigate the Recalbox menu, none of the buttons are being detected within the controller configuration menu.
Has anyone experienced a similar issue, or can offer any insights into why this might be happening? Your help would be immensely appreciated to get my custom controller fully operational with Recalbox.
Thank you in advance!
Here is my arduino code:
`/*
Select: button8
Start: button9
Hotkey: button9
L: button4 (Joystick L button)
R: button5 (Joystick R button)
X: button0
Y: button3
A: button1
B: button2
D-U: axis 1-
D-D: axis 1+
D-L: axis 0-
D-R: axis 0+
*/
#include <Gamepad.h>
//left joystick
int leftXcenter = 500;
int leftYcenter = 500;
double multiplierLX = 0.254;
double multiplierLY = 0.254;
//right joystick
int rightXcenter = 500;
int rightYcenter = 500;
double multiplierRX = 0.254;
double multiplierRY = 0.254;
Gamepad gp;
void setup() {
//Left joystick
pinMode(A0, INPUT);
pinMode(A1, INPUT);
//Right joystick
pinMode(A2, INPUT);
pinMode(A3, INPUT);
//Start, Select buttons
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
//ABXY
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
//LR
pinMode(8, INPUT_PULLUP); //Joystick L button
pinMode(9, INPUT_PULLUP);//Joystick R button
calibrate();
}
void loop() {
int lx, ly, rx, ry;
//left joystick
lx = analogRead(A0);
ly = analogRead(A1);
lx = floor((lx - leftXcenter) * multiplierLX);
ly = floor((ly - leftYcenter) * multiplierLY);
if(lx > 127) lx = 127;
if(ly > 127) ly = 127;
gp.setLeftXaxis(lx);
gp.setLeftYaxis(ly);
//right joystick
rx = analogRead(A2);
ry = analogRead(A3);
rx = floor((rx - rightXcenter) * multiplierRX);
ry = floor((ry - rightYcenter) * multiplierRY);
if(rx > 127) rx = 127;
if(ry > 127) ry = 127;
gp.setRightXaxis(rx);
gp.setRightYaxis(ry);
int select, start, a, b, x, y, l, r;
select = digitalRead(2);
start = digitalRead(3);
a = digitalRead(4);
b = digitalRead(5);
x = digitalRead(6);
y = digitalRead(7);
l = digitalRead(8);
r = digitalRead(9);
if(select == LOW)
gp.setButtonState(8, true);
else
gp.setButtonState(8, false);
if(start == LOW)
gp.setButtonState(9, true);
else
gp.setButtonState(9, false);
if(a == LOW)
gp.setButtonState(1, true);
else
gp.setButtonState(1, false);
if(b == LOW)
gp.setButtonState(2, true);
else
gp.setButtonState(2, false);
if(x == LOW)
gp.setButtonState(0, true);
else
gp.setButtonState(0, false);
if(y == LOW)
gp.setButtonState(3, true);
else
gp.setButtonState(3, false);
//L R button
if(l == LOW)
gp.setButtonState(4, false);
else
gp.setButtonState(4, true);
if(r == LOW)
gp.setButtonState(5, false);
else
gp.setButtonState(5, true);
delay(20);
}
void calibrate()
{
int lx, ly, rx, ry;
int i = 0;
while(i < 8)
{
lx = analogRead(A0);
ly = analogRead(A1);
bool validLX = lx > (leftXcenter - 100) && lx < (leftXcenter + 100);
bool validLY = ly > (leftYcenter - 100) && ly < (leftYcenter + 100);
rx = analogRead(A2);
ry = analogRead(A3);
bool validRX = rx > (rightXcenter - 100) && rx < (rightXcenter + 100);
bool validRY = ry > (rightYcenter - 100) && ry < (rightYcenter + 100);
if(validLX && validLY && validRX && validRY)
{
i++;
//nothing to do here!
}
else i = 0;
delay(20);
}
leftXcenter = lx;
leftYcenter = ly;
multiplierLX = (double)127 / (double)lx;
multiplierLY = (double)127 / (double)ly;
rightXcenter = rx;
rightYcenter = ry;
multiplierRX = (double)127 / (double)rx;
multiplierRY = (double)127 / (double)ry;
}
`
In the readme the setters for the axes all expect an uint8_t but that should be an int8_t.
Hi, is possible to add more than 16 buttons?
I used this site: https://gamepad-tester.com/
and validated everything works - which (after having no luck with the alternatives) was a wonderful surprise. Of course, now that means I have no excuses not to build the hardware I'd promised my little trainee. Drat and triple drat!
Programmed my arduino Leonardo on my Linux machine and it works as a gamepad, however it doesn't recognize on my Mac.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.