Created
October 11, 2011 01:25
-
-
Save cfaulkingham/1277044 to your computer and use it in GitHub Desktop.
Code for adding joystick support to the Gameduino Frogger game.
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
class Controller { | |
public: | |
void begin() { | |
byte i; | |
for (i = 3; i < 7; i++) { | |
pinMode(i, INPUT); | |
digitalWrite(i, HIGH); | |
} | |
prev = 0; | |
} | |
byte read() { | |
int x = analogRead(0); | |
int y = analogRead(1); | |
byte r = 0; | |
if (!digitalRead(5) || y==0) | |
r |= CONTROL_DOWN; | |
if (!digitalRead(4) || y==1023) | |
r |= CONTROL_UP; | |
if (!digitalRead(6) || x==0) | |
r |= CONTROL_LEFT; | |
if (!digitalRead(3) || x==1023) | |
r |= CONTROL_RIGHT; | |
byte edge = r & ~prev; | |
prev = r; | |
return edge; | |
} | |
private: | |
byte prev; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment