Olivia Cueva and I paired up to make our own game controller to the classic Luna Lander in a web browser. The requirements were to build a controller that controls the characters keys on the keyboard of W,A,S, and D and optionally make the mouse move and click (not part of the game, but preparing to play). We had to fabricate housing for our controller to hide all of our electrical components, and make it be usable to play without moving the eyes of the screen. The controller housing we built has four buttons to control the keyboard letters above as well as a joystick to control the movement and click of the mouse.  The housing is constructed from cardboard and covered in fabric.

Here it is at play –

Olivia had a similar button code from her a game she made (The Rihanna Game) and so we had a sample code to start with, based on it and on class example. She got it working on the Arduino Leonardo.

We tested it on the breadboard and it worked.

 

I drew the schematics for the 4 buttons switches.

I wanted to test out the Feathers, as initially had a thought to make the controller very small. I checked out the Feather  M0 from the ER and soldered the pins in place, then updated the the board through the Arduino IDE Board Manager. I got this error a few times, then after trying out

I emailed Tom about it and he replied with these options:

1. make sure you install the Feather M0 board definitions. IN Preferences, under “Additional Boards Manager URLs”, add the following URL:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json. Then in the Boards manager, search for “Feather M0” and install the “Adafruit SAMD boards” which should come up i the search.
2. Restart Arduino IDE just for good measure.
3. Make sure you’ve chosen the Feather M0 in the boards menu
4. Make sure you’ve chosen the Feather M0 in the Port menu
5. If it doesn’t upload now, double-press the restart button and try again.
–> I DID options 1, 3 and 4 but by the time I got his reply,then we were way on our way designing our house for the Leonardo. So I need to retry the Feather  M0 tomorrow.

 

Fabricating

We experimented with some boxes we already had and a tupperware but ultimately decided to cut our own box out of cardboard with the laser cutter. We found a box template online, pulled it into illustrator and adjusted the size and shape to make space for the breadboard inside and the joystick. We decided on this design, 4 buttons on the top box and the joystick to get into the game on the front panel. When printing on the laser cutter I wanted to add the guides for folding. At first I added raster lines, and cut one box. To be sure we get it right, we cut another box, because the plan was also to cover the entire box with fabric. Since the rasterizing takes very long, I thought about running the vector cutting just on low power, and thinner line. This went well, and is a good trick for me to remember for future marking on the laser cutter. 

We cut the box out of found cardboard in the shop, but once we cut and assembled it, we realized that the cardboard was too thick for the head of our buttons to come out, so I added a little drop of hot glue to the tops of each button so that they still were functional and clicked.

The process of soldering and the making of the box took a pretty long time with planning and re-planning how to house the wires and get it all fixed in one place. Next time, I hope we’ll be able to use the flexible wires.

 

after trying to work with breadboard and realizing that it will be to crowded, and unnecessary I soldered the all the power and grounds in parallel so only had to have 6 wires going into the Leonardo.

Some questions came up:

why don’t we need to use Serial.begin(9600)? guessed answer – we are not using serial communication as we’re using usb.

whats the difference between Keyboard.print() vs. Keyboard.write() vs. Keyboard.press() functions – guessed answer with the ASCII characters

when we tested one button, and the Leonardo was sitting on the table, it was mixing letter, instead of doing the designated letter, for example ‘a’, it would randomly write ‘d’ or ‘s; we couldn’t understand why, then thought it might be because of conductivity that activates the pin.. no sure yet.

The code used:

#include <Keyboard.h>
// set up variables that remain constant (“const int”) and those that may change (“int”) to the pins on the arduino
const int buttonPinA = 2;
const int buttonPinW = 3;
const int buttonPinS = 4;
const int buttonPinD = 5;
//int buttonState = 0;

void setup() {
// set button as input to recieve incoming data
pinMode(buttonPinA, INPUT);
pinMode(buttonPinW, INPUT);
pinMode(buttonPinS, INPUT);
pinMode(buttonPinD, INPUT);
Keyboard.begin();
}

void loop() {
// put your main code here, to run repeatedly:

// if the button is pressed, write letter ‘a’
if (digitalRead(buttonPinA) == HIGH) {
Keyboard.press(‘a’);
delay(100);
}
// if button is not pressed, release letter ‘a’
else if (digitalRead(buttonPinA) == LOW) {
Keyboard.release(‘a’);
}
// if the button is pressed, write letter ‘w’
if (digitalRead(buttonPinW) == HIGH) {
Keyboard.press(‘w’);
delay(100);
}
// if button is not pressed, release letter ‘w’
else if (digitalRead(buttonPinW) == LOW) {
Keyboard.release(‘w’);
}
// if the button is pressed, write letter ‘s’
if (digitalRead(buttonPinS) == HIGH) {
Keyboard.press(‘s’);
delay(100);
}
// if button is not pressed, release letter ‘s’
else if (digitalRead(buttonPinS) == LOW) {
Keyboard.release(‘s’);
delay(100);
}
// if the button is pressed, write letter ‘d’
if (digitalRead(buttonPinD) == HIGH) {
Keyboard.press(‘d’);
delay(100);
}
// if button is not pressed, release letter ‘d’
else if (digitalRead(buttonPinD) == LOW) {
Keyboard.release(‘d’);
}
}