Final Project: game controller


My Physical computer project is a an game controller used to control Arduino







The game that I created in my Major Studio coarse is used to create this project.

The controller would be used to move the character forward and back, and activate a jump button, and attack button.


At first I tried using the Serial port to communicate with the Arduino. But serial communication
has been blocked from the latest versions of unity. After I used our instructor’s advice to convert
text using a function to change ASCII characters to keyboard command. It was blocked because
only Arduino Leonardo’s are allowed





Finally I used the Firmata code and a plugin called Uniduino
to write code for the Arduino. Firmata was used to bounce communication for Arduino
While communicating Unity would use C sharp to communicate to the other side.
This is new code written in C sharp  was not shown in the final presentation.




using UnityEngine;
using System.Collections;
using Uniduino;

#if (UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5)
public class BlinkButton : Uniduino.Examples.BlinkButton { } // for unity 3.x

namespace Uniduino.Examples

public class BlinkButton : MonoBehaviour {

public Arduino arduino;
//starting out the pins to
public int f_button_pin = 9;
public int b_button_pin = 10;
public int a_button_pin = 11;
public int j_button_pin = 12;
// Use this for initialization
void Start () {

arduino =;
arduino.Log = (s) => Debug.Log(“Arduino: ” +s);


ConfigurePins ();

void ConfigurePins ()
Debug.Log(“set pin mode”);
arduino.pinMode(f_button_pin, PinMode.OUTPUT);
arduino.pinMode(b_button_pin, PinMode.OUTPUT);
arduino.pinMode(a_button_pin, PinMode.OUTPUT);
arduino.pinMode(j_button_pin, PinMode.OUTPUT);

void OnGUI()
GUILayout.BeginArea(new Rect(100, 100, Screen.width-100, Screen.height-100));
if (GUILayout.Button(“Press me”, GUILayout.Width(200)))


IEnumerator GameControllers(){
if ((grounded || !doubleJump) && arduino.digitalWrite(j_button_pin, Arduino.LOW);) {
anim.SetBool (“Ground”, false);
rigidbody2D.AddForce (new Vector2 (0, jumpForce));

if(!doubleJump && !grounded)
doubleJump = true;


arduino.digitalWrite(j_button_pin, Arduino.HIGH);
yield return new WaitForSeconds(1);

if arduino.digitalWrite(f_button_pin, Arduino.LOW);) {
moving.y = 1;
} else if arduino.digitalWrite(b_button_pin, Arduino.LOW);) {
moving.y = -1;



// Update is called once per frame
void Update () {








Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s