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

31 thoughts on “Game Controller”

  1. I happen to be writing to make you understand what a terrific experience our princess went through visiting yuor web blog. She realized such a lot of things, with the inclusion of what it is like to possess an incredible teaching style to make the others without hassle thoroughly grasp various tricky topics. You undoubtedly surpassed visitors’ expected results. Thanks for showing those valuable, trustworthy, revealing not to mention unique tips on your topic to Sandra.

  2. Thank you for each of your hard work on this web page. My aunt really likes going through investigations and it’s really obvious why. Most of us learn all of the lively method you offer practical strategies through this web site and even increase participation from some other people on the issue so our favorite girl is in fact learning a lot of things. Take advantage of the rest of the year. You are always doing a really good job.

  3. I am glad for writing to make you know what a notable encounter my wife’s girl had studying your web site. She mastered several pieces, which include what it’s like to possess an awesome helping nature to let other individuals with ease know precisely some problematic subject matter. You truly exceeded people’s expectations. Thank you for producing these practical, trusted, informative and in addition fun tips about this topic to Kate.

Leave a Reply

Your email address will not be published.