Last active
December 14, 2015 19:09
-
-
Save jrmedd/5134333 to your computer and use it in GitHub Desktop.
Awkward Pac-Man Controller - Digispark
Blog post: http://jamesmedd.tumblr.com/post/45119890963/awkward-arcade-motion-controller-for-pac-man
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DigiKeyboard.h" | |
int tilt = 0; | |
int leftUp = 1; | |
int rightDown = 2; | |
void setup() { | |
pinMode(tilt, INPUT); | |
pinMode(leftUp, INPUT); | |
pinMode(rightDown, INPUT); | |
} | |
void loop() { | |
DigiKeyboard.update(); | |
int tiltState = digitalRead(tilt); | |
int leftUpState = digitalRead(leftUp); | |
int rightDownState = digitalRead(rightDown); | |
if (tiltState == HIGH) { | |
if (leftUpState == HIGH) { | |
DigiKeyboard.sendKeyStroke(KEY_W); | |
} | |
if (rightDownState == HIGH) { | |
DigiKeyboard.sendKeyStroke(KEY_S); | |
} | |
} | |
else { | |
if (leftUpState == HIGH) { | |
DigiKeyboard.sendKeyStroke(KEY_A); | |
} | |
if (rightDownState == HIGH) { | |
DigiKeyboard.sendKeyStroke(KEY_D); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment