Skip to content

Instantly share code, notes, and snippets.

@Tiriree
Created February 1, 2017 06:31
Show Gist options
  • Save Tiriree/75b5a12a4208d3484f3835225364adc2 to your computer and use it in GitHub Desktop.
Save Tiriree/75b5a12a4208d3484f3835225364adc2 to your computer and use it in GitHub Desktop.
Game controller with HID output for Tangible Interaction Tom IGOR
/*
KeyboardControl for Game controller
tangible workshop's assignments - wed
using https://www.arduino.cc/en/Reference/KeyboardModifiers
inspired by Tom Igoe
and help from Lola <3
*/
#include "Keyboard.h"
// set pin numbers for the five buttons:
char up = KEY_UP_ARROW;
char down = KEY_DOWN_ARROW;
char left = KEY_LEFT_ARROW;
char right = KEY_RIGHT_ARROW;
void setup() { // initialize the buttons' inputs:
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
// use the pushbuttons to control the keyboard:
if (digitalRead(2) == HIGH) {
delay(100);
Keyboard.press(up);
}
delay(100);
Keyboard.releaseAll();
if (digitalRead(3) == HIGH) {
delay(100);
Keyboard.press(down);
}
delay(100);
Keyboard.releaseAll();
if (digitalRead(4) == HIGH) {
delay(100);
Keyboard.press(left);
}
delay(100);
Keyboard.releaseAll();
if (digitalRead(5) == HIGH) {
delay(100);
Keyboard.press(right);
}
delay(100);
Keyboard.releaseAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment