Created
May 4, 2013 08:54
-
-
Save jrmedd/5516875 to your computer and use it in GitHub Desktop.
Use Mega Drive pad on PS3. Requires Unojoy (http://code.google.com/p/unojoy/) A = Circle
B = Cross
C = Square
Start + Up = Home Button Start + Down = Select
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 "UnoJoy.h" | |
int up = 2; | |
int down = 3; | |
int left = 4; | |
int right = 5; | |
int ab = 6; | |
int slct = 7; //setting this pin HIGH/LOW reads A/B and Start/C | |
int startc = 8; | |
void setup() { | |
for (int i = 2; i <= 6; i += 1){ | |
pinMode(i, INPUT); | |
} //pins 1-6 inputs | |
pinMode(slct, OUTPUT); //'select' pin is an output | |
pinMode(startc, INPUT); | |
setupUnoJoy(); | |
} | |
void loop() { | |
dataForController_t controllerData = getControllerData(); | |
setControllerData(controllerData); //Unojoy loop taken from example sketch | |
} | |
dataForController_t getControllerData(void) { | |
dataForController_t controllerData = getBlankDataForController(); | |
digitalWrite(slct, LOW); //set 'select' LOW to read A and Start | |
controllerData.squareOn = !digitalRead(ab); //UJ data is inverse of pad data | |
if (digitalRead(startc) == LOW && digitalRead(up) == LOW) { | |
controllerData.homeOn = HIGH; //Start and Up for Home button | |
} | |
else { | |
controllerData.homeOn = LOW; | |
controllerData.dpadUpOn = !digitalRead(up); | |
controllerData.startOn = !digitalRead(startc); | |
} | |
if (digitalRead(startc) == LOW && digitalRead(down) == LOW) { | |
controllerData.selectOn = HIGH; //Start and Down for Select Button | |
} | |
else { | |
controllerData.selectOn = LOW; | |
controllerData.dpadDownOn = !digitalRead(down); | |
} | |
digitalWrite(slct, HIGH); //set 'select' HIGH to read B and C | |
controllerData.dpadLeftOn = !digitalRead(left); | |
controllerData.dpadRightOn = !digitalRead(right); | |
controllerData.crossOn = !digitalRead(ab); | |
controllerData.circleOn = !digitalRead(startc); | |
return controllerData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment