You are on page 1of 4

PSX Library

Commands:

setupPins(dataPin, cmndPin, attPin, clockPin, delay)

Defines which pins on the arduino are connected to the


controller, as well as the delay on how long the clock
remains high and low.
Ex: Psx.setupPins(2, 3, 4, 5, 10)
read()

Reads the button data from the playstation controller,


and returns it as an unsigned integer.
Ex: data = Psx.read();

The returned data is an unsigned integer, with each bit


representing a specific button. It can be tested using a
simple if statement.

Ex: if (data & psxUp)

Each button is defined in the library, so there is no need to


use hex codes when testing.

psxLeft 0x0001
psxDown 0x0002
psxRight 0x0004
psxUp 0x0008
psxStrt 0x0010
psxSlct 0x0080
psxSqu 0x0100
psxX 0x0200
psxO 0x0400
psxTri 0x0800
psxR1 0x1000
psxL1 0x2000
psxR2 0x4000
psxL2 0x8000
#include <Psx.h> // Includes the Psx Library

// Any pins can be used since it is done in software

#define dataPin 8

#define cmndPin 9

#define attPin 11

#define clockPin 10

#define LEDPin 13

Psx Psx; // Initializes the library

unsigned int data = 0; // data stores the controller response

void setup()

Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10); // Defines what each

pin is used

// (Data Pin #, Cmnd Pin #, Att Pin #, Clk Pin #, Delay)

// Delay measures how long the clock remains at each state,

// measured in microseconds.

// too small delay may not work (under 5)


pinMode(LEDPin, OUTPUT); // Establishes LEDPin as an output so the LED

//can be seen

Serial.begin(9600);

void loop()

data = Psx.read(); // Psx.read() initiates the PSX controller and returns

// the button data


Serial.println(data); // Display the returned numeric value

if (data & psxR2) // If the data anded with a button's hex value is true,

// it signifies the button is pressed. Hex values for each

// button can be found in Psx.h

digitalWrite(LEDPin, HIGH); // If button is pressed, turn on the LED

else

digitalWrite(LEDPin, LOW); // If the button isn't pressed, turn off the LED

delay(20);

You might also like