Creating an Arduino Gaming Controller Need Help Sending Commands

Hello everyone,

I've been working with Arduino for a little over a month now, and I'm currently trying to create a gaming controller. However, I'm new to coding and could use some help figuring out how to send commands from buttons and a joystick to an Android app named Toca Boca APK.

Here's a sketch of what I've done so far:
#include <HC05.h>
#include <maker_joystick.h>
#include <Pushbutton.h>

int PushbuttonA = 8;
int PushbuttonB = 9;
int PushbuttonC = 10;
int PushbuttonD = 11;
int maker_joystick = 2;
int HC05 = 1;
const int inPressed = 2;
const int inX = A0; // analog input for x-axis
const int inY = A1; // analog input for y-axis
int xValue = 0;
int yValue = 0;
int buttonStateA = LOW;
int buttonStateB = LOW;
int buttonStateC = LOW;
int buttonStateD = LOW;
int connected = 1;

void setup() {
pinMode(PushbuttonA, INPUT);
pinMode(PushbuttonB, INPUT);
pinMode(PushbuttonC, INPUT);
pinMode(PushbuttonD, INPUT);
pinMode(maker_joystick, INPUT);
pinMode(HC05, OUTPUT);
digitalWrite(HC05, HIGH);
pinMode(inPressed, INPUT);
}

void loop() {
digitalWrite(HC05, HIGH);

// Read button states
buttonStateA = digitalRead(PushbuttonA);
buttonStateB = digitalRead(PushbuttonB);
buttonStateC = digitalRead(PushbuttonC);
buttonStateD = digitalRead(PushbuttonD);

// Handle button presses
if (buttonStateA == HIGH) {
// Send command to shoot
// Example: sendCommand("shoot");
}
if (buttonStateB == HIGH) {
// Send command to use scope
// Example: sendCommand("scope");
}
if (buttonStateC == HIGH) {
// Send command to crouch
// Example: sendCommand("crouch");
}
if (buttonStateD == HIGH) {
// Send command to jump
// Example: sendCommand("jump");
}

// Read joystick values
xValue = analogRead(inX);
yValue = analogRead(inY);

// Map joystick values to actions (if needed)
// Example: mapJoystickToActions(xValue, yValue);

delay(100); // Adjust delay as needed
}

// Function to send commands to Toca Boca APK
void sendCommand(String command) {
// Implement code to send commands via Bluetooth or other communication protocol
}

// Function to map joystick values to actions
void mapJoystickToActions(int x, int y) {
// Implement mapping logic based on joystick readings
}
I'm particularly struggling with how to effectively send commands from the buttons (A, B, C, D) and the joystick (X and Y axis) to control actions in the Toca Boca APK. Any guidance or suggestions on how to improve my code would be greatly appreciated!

Looking forward to your insights. Thanks!

Welcome to the forum

You started a topic in the Uncategorised category of the forum when its description explicitly tells you not to

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Does Toca Boca expose a communication API that allows you to interact with it?

What type of transport does it use, BLE, Classic Bluetooth, WIFI?

What Arduino do you wish to use? Does it support the required transport?

For a new programmer, this is an ambitious task.

Could you provide some more details? I'am currently working on a hid steering wheel for a while now so I can get you started! So already a gaming controller for like a first project is insanely tough. Ok, so firstly does it have to be for android or something else? Because if it is for example a game controller for pc then go ahead with the joystick library. Need vibrations or ffb go ahead with ranenbegs ffb firmware or the joystick library with ffb. If it is for android well I can't help you much then. I've never worked with Android. Please provide some more details.

not at all, so easy like a "Blink"

@nickpeter kick me if you are clear what BT must send as command line.

I mean yeah if you go the easy way and download something like emc for steering wheels or just apply a hex like most of them do then yeah it is quite easy but if the original poster wanted to tweak the code and play around with it then its not so easy.

And what exactly do you mean by

Bluetooth isn't really a communication protocol. Are you trying to send it wirelessly?
Ok so first of making a game and making a gaming controller aren't the same things. Does it have to act like a regular controller? If so what are you trying to do with that APK? Making a controller isn't as simple as: IF I CLICK X THEN: JUMP. Gaming controllers have really complex hid protocols. If you want to build a real gaming controller then you have to either make and write the whole hid code yourself or like any other sane person use a library like the Joystick library. It is really well explained and handles all communication protocols for you so you pretty much don't have to do anything. The library:

Toca Boca does not expose a communication API for external interaction. Consequently, there is no specific transport protocol (such as BLE, Classic Bluetooth, or WiFi) associated with it.

When considering Arduino projects, the choice of Arduino model depends on the specific requirements of your project. For instance, if you need WiFi capabilities, the Arduino Uno WiFi Rev2 or the Arduino MKR WiFi 1010 could be suitable choices. For Bluetooth, the Arduino Nano 33 BLE could be appropriate.

However, given that Toca Boca does not support external communication, integrating it with an Arduino would not be feasible. For a new programmer, it's important to choose a project with well-documented APIs and support to ensure a successful learning experience.

thank you for your guidence mate.

  1. Platform:
  • PC: Use the Joystick library for Arduino.
  • Android: More complex; not recommended for beginners.
  1. Arduino Model:
  • Use Arduino Leonardo or Micro for USB HID support.
  1. Libraries/Firmware:
  • Joystick Library: For creating USB HID devices.
  • FFB: Use ranenb’s FFB firmware if force feedback is needed.
  1. Connectivity:
  • PC: Direct USB connection with Arduino Leonardo/Micro.
  • Android: Requires Bluetooth or USB OTG, which is more complex.

Focus on a PC-based project with the Joystick library for simplicity and better support.

Well if you need to make it for android then I can't help you anymore.

No, Toca Boca does not provide a public API or communication interface for external interaction. Toca Boca World apps are primarily standalone, designed for children’s interactive play without online multiplayer or external API support, focusing instead on privacy and safe, offline experiences.

Applebee’s Happy Hour is a popular time for customers to enjoy discounted drinks after a long day or a night out with friends. Still, many customers are unaware of the discounted deals and specific hours of Applebee’s Happy Hour. To address this issue, Applebee’s happy hour implements a strong marketing strategy by posting regular social media posts, email newsletters, and app notifications for regular customers. That’s why, Applebee’s happy hour is getting customers’ satisfaction. Now in this article, we are going to provide you with complete details of Applebee’s Happy Hour Menu With Prices. [visit now](https://applebeeeshappyhour.com/)