Game Controller

ok THIS IS OMRI’S GAME CONTROLLER CODE AND SET UP

we are now using an arduino leonardo
it has an inbuilt library for HID and keyboard serial

we can replicate the keyboard commands off the controller
http://www.games.fm/the-choice.html

++++++++++++++++++++

//keyboard controller
//omri 2015

// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;
void setup() { // initialize the buttons’ inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);

Serial.begin(9600);
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
}

void loop() {
// // use serial input to control the mouse:
// if (Serial.available() > 0) {
// char inChar = Serial.read();
//
// switch (inChar) {
// case ‘u’:
// // move mouse up
// Mouse.move(0, -40);
// break;
// case ‘d’:
// // move mouse down
// Mouse.move(0, 40);
// break;
// case ‘l’:
// // move mouse left
// Mouse.move(-40, 0);
// break;
// case ‘r’:
// // move mouse right
// Mouse.move(40, 0);
// break;
// case ‘m’:
// // perform mouse left click
// Mouse.click(MOUSE_LEFT);
// break;
// }
// }

// use the pushbuttons to control the keyboard:
if (digitalRead(upButton) == HIGH) {
Keyboard.write(‘w’);
delay(50);
}
if (digitalRead(downButton) == HIGH) {
Keyboard.write(‘s’);
}
if (digitalRead(leftButton) == HIGH) {
Keyboard.write(‘a’);
}
if (digitalRead(rightButton) == HIGH) {
Keyboard.write(‘d’);
}
if (digitalRead(mouseButton) == HIGH) {
Keyboard.write(‘ ‘);
}

}