So. I made a gamepad with an arduino leonardo using this library.
I connected it to my computer with USB - it worked perfectly.
I connected it to my tablet with USB (OTG) - it worked perfectly.
Now I'm trying to implement bluetooth using an HC-06, but I can't find anything to guide me. I investigated, and while I could pair my device with the HC-06, I found that I need a "vessel" program or something like that so the HC-06 links to my android device properly. I tried to search for the solution, but instead of finding how to control android with an arduino, I just found lots of videos and tutorials about how to control an arduino with android :))
So now I can't find anything to guide me in this project, I don't know how to send bluetooth information to my android device just as it does via USB. Is there any app, program or library that I can use to make it possible?
Here's my code:
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
8, 0,
true, true, false,
false, false, false,
false, false,
false, false, false);
void setup() {
// Initialize Button Pins
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
Joystick.setXAxisRange(-1, 1);
Joystick.setYAxisRange(-1, 1);
}
// Last state of the buttons
int lastButtonState[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
void loop() {
// Read pin values
for (int index = 0; index < 12; index++)
{
int currentButtonState = !digitalRead(index + 2);
if (currentButtonState != lastButtonState[index])
{
switch (index) {
case 0: // UP
if (currentButtonState == 1) {
Joystick.setYAxis(-1);
} else {
Joystick.setYAxis(0);
}
break;
case 1: // RIGHT
if (currentButtonState == 1) {
Joystick.setXAxis(1);
} else {
Joystick.setXAxis(0);
}
break;
case 2: // DOWN
if (currentButtonState == 1) {
Joystick.setYAxis(1);
} else {
Joystick.setYAxis(0);
}
break;
case 3: // LEFT
if (currentButtonState == 1) {
Joystick.setXAxis(-1);
} else {
Joystick.setXAxis(0);
}
break;
case 4: // A
Joystick.setButton(0, currentButtonState);
break;
case 5: // B
Joystick.setButton(1, currentButtonState);
break;
case 6: // X
Joystick.setButton(2, currentButtonState);
break;
case 7: // Y
Joystick.setButton(3, currentButtonState);
break;
case 8: // START
Joystick.setButton(4, currentButtonState);
break;
case 9: // SELECT
Joystick.setButton(5, currentButtonState);
break;
case 10: // L
Joystick.setButton(6, currentButtonState);
break;
case 11: // R
Joystick.setButton(7, currentButtonState);
break;
}
lastButtonState[index] = currentButtonState;
}
}
delay(10);
}