Game Controller

For this assignment, I created a game controller to play Atari’s Lunar Lander game in a browser. Using buttons, the controller sends W(up), S(down), A(left) and D(right) keypresses as a USB keyboard.

I used the MKR1000 board for this assignment. The device uses bluetooth connection but I connected it via USB directly to the computer for power and connection.

Code

#include “Keyboard.h”

const int upButton = 7;
const int downButton = 8;
const int leftButton = 6;
const int rightButton = 9;
//const int reloadButton = 4;
//const int enterButton = 5;
void setup () {
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
// pinMode(reloadButton, INPUT);
// pinMode(enterButton, INPUT);

//Serial.begin();
Keyboard.begin();
}

void loop() {

//keyboard button presses
if (digitalRead(upButton) == HIGH) {
Keyboard.press(‘w’); //send UP
delay(100);
}
else if (digitalRead(upButton) == LOW)
Keyboard.release(‘w’);

if (digitalRead(downButton) == HIGH) {
Keyboard.press(‘s’); //send DOWN
delay(100);
}
else if (digitalRead(downButton) == LOW)
Keyboard.release(‘s’);

if (digitalRead(leftButton) == HIGH) {
Keyboard.press(‘a’); //send LEFT
delay(100);
}
else if (digitalRead(leftButton) == LOW)
Keyboard.release(‘a’);

if (digitalRead(rightButton) == HIGH) {
Keyboard.press(‘d’); //send RIGHT
delay(100);
}
else if (digitalRead(rightButton) == LOW)
Keyboard.release(‘d’);

Circuit Design

Fabrication

Materials:

Matboard
Buttons
Wires
Bamboo box
Breadboard

Process:

Solder header pins to the MKR1000
Solder wires to the 4 buttons
Connect the buttons and MRK1000 to breadboard

 

Citations

Arduino mouse and keyboard libraries

Arduino mouse button control

Leave a Reply

Your email address will not be published.