So, i've made my first game in Processing, and now i want to control it with my Arduino instead of the keyboard. I've googled the crap out of this, and i've found instructions for different steps, but i just can't get it right all together.
I want to build the control by myself with a joystick and buttons, or use my Funduino joystick shield (might be easier?) So i guess i need help with schematics, and help with the communication/code in Processing and Arduino.
Here's my game: https://dl.dropboxusercontent.com/u/16344470/starwars_game.zip
(And keep in mind that it's the first game i've ever made, hehe)
Please help a sister out! 
Hello lillesneck,
Building a controller will not be a problem but connecting an Arduino via USB to control the keyboard is something something that the Arduino does not do well. If you have a Due or zero or other Atmega32u4 board, you can use the Mouse and Keyboard library, which too isnt the best way to do it. With an Uno/Atmega8u2, it is even more of a task
I suggest you use a Teensy Board(found this here). Google "getting started with Teensy" to see more about htis board. Here is what you need to do.
Or you could even search "how to make a usb joystick" to see other alternatives.
Hope that helps. Just ask if you have any more questions.
Btw, I downloaded your game but how do I open it :p. Is it even made for Windows?
Also it is always better to not use shields but direct parts itself as you get more flexibility on pin selection and I feel that you get to learn more.
A joystick is nothing but two potentiometers, one for each axis, X and Y. So when you move the joystick you are actually moving the slider/variable end on the potentiometer. This changes the potential at the slider/variable end which is detected by the arduino. Here is a short video tutorial.

Once you can get values off a joystick, you can accordingly send commands(eg. if x==0, usb.print("UP") elseif x==1023, usb.print("DOWN") ) via USB to the game which is the actual task in this project.
Btw, I downloaded your game but how do I open it :p. Is it even made for Windows?
She told you:-
i've made my first game in Processing,
Processing is a language it runs on all platforms.
Or you could even search "how to make a usb joystick"
No - do you know nothing the game is running in Processing - you do not want a USB joystick.
@lillesneck
To communicate with processing from an Arduino you use the serial port. This tutorial covers the basics:-
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing
Stay clear of Firmatta and write your own code on the Arduino. Send messages from the Arduino and receive them in Processing.
Grumpy_Mike:
She told you:-Processing is a language it runs on all platforms.
No - do you know nothing the game is running in Processing - you do not want a USB joystick.
@lillesneck
To communicate with processing from an Arduino you use the serial port. This tutorial covers the basics:-
Connecting Arduino to Processing - SparkFun Learn
Stay clear of Firmatta and write your own code on the Arduino. Send messages from the Arduino and receive them in Processing.
Oooh! I didnt know that Processing is some language, sorry for the confusion...and thanks for clearing me up!
Can processing read HID sticks plugged into the PC?
You can make your own stick and program it as HID using an Arduino Micro. They have ATmega32U4 chips that make it easy and communicate at full USB speed, not 115200 baud serial.
Also if you build the actual stick.. don't use pots. Use magnet and linear Hall sensor pairs like the better sticks have for over 15 years now.
Whatever you decide; if there's any step you don't completely know, make a small project to explore and develop that one single aspect.
I personally suggest that you get into DIY capacitive sensing just to check the possibilities.
You can make your own stick and program it as HID using an Arduino Micro.
I am not aware of any code to make and Arduino look like a HID joystick.
You can program it to be a keyboard or mouse or even a USB MIDI device but I have not seen a joystick in the
PluggableUSB system.
When I did it, it was on a Teensy++ 2.0 using PJRC's software before the Leonardo or Micro was invented. Paul Stoffgren made the software available. You can do keyboard, mouse and stick at the same time if you don't block.
http://www.pjrc.com/teensy/td_joystick.html
The Teensy++ 2.0 has moar pins and 8K RAM. The 3.x makes it look poor.
Thank you for your reply!
I have this joystick: http://ecx.images-amazon.com/images/I/41hxVjILi%2BL.jpg
What i want to do is control the ship with the joystick and shoot enemies with a button. I know how to set up the connection between Arduino & processing, so i guess i need help with how to change the processing-code to work with the joystick + button instead of the keyboard. And maybe the techstuff with the joystick and the button (newbie) hehe.
Srijal97:
Hello lillesneck,
Building a controller will not be a problem but connecting an Arduino via USB to control the keyboard is something something that the Arduino does not do well. If you have a Due or zero or other Atmega32u4 board, you can use the Mouse and Keyboard library, which too isnt the best way to do it. With an Uno/Atmega8u2, it is even more of a task
I suggest you use a Teensy Board(found this here). Google "getting started with Teensy" to see more about htis board. Here is what you need to do.
Or you could even search "how to make a usb joystick" to see other alternatives.
Hope that helps. Just ask if you have any more questions.
Btw, I downloaded your game but how do I open it :p. Is it even made for Windows?
First you have to establish a link between the Arduino and Processing to do this:-
Add this line to the start of the code:-
import processing.serial.*;
String adaptor = "/dev/cu.SLAB_USBtoUART"; // *** change to the name of the device driver to use ***
This is the name of the port you want to connect to, get it from the Arduino IDE when you connect your arduino up to down load code.
Then in the setup function add this line
portConnect();
Finally add this function
void portConnect(){ // Open the port that is the arduino
// **********************************
// if the device you are looking for is
// not avaliable the program will
// connect to the first one in the list
// ************************************
int portNumber = 99;
String [] ports;
// println(Serial.list()); // uncomment for full list of serial devices
ports = Serial.list();
for(int j = 0; j< ports.length; j++) {
if(adaptor.equals(Serial.list()[j])) portNumber = j;
} // go through all ports
if(portNumber == 99) portNumber = 0; // if we haven't found our port connect to the first port
String portName = Serial.list()[portNumber];
println("Connected to "+portName);
// port = new Serial(this, portName, 57600);
port = new Serial(this, portName, 38400);
port.bufferUntil(10); // call serialEvent every line feed
}
Now to listen to what the Arduino sends add this function stub
void serialEvent(Serial port) { // this gets called every time a line feed is received
String recieved = port.readString() ;
// println(recieved + " from serial port");
// add stuff exactly like your keyPressed() function to do stuff on receipt of characters from the Arduino
}
Now your Arduino has to talk to processing:-
Set your Arduino to send at 38400 baud.
Get your Arduino to send single characters followed by a line feed by using things like:-
Serial.println("U");
Do this with push buttons at first controlling what is being sent. Only when this is going, extend it to read the joystick.