WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Sony PS2

Adds support for the Sony Playstation PS2 controllers.
Thanks to 'Dunk' for his contributions, testing and patience. Other thanks to Bill Porter.
These controllers come with a 9 pin plug - which you will need to cut off and replace with your own header pin sockets. Alternatively you can find adaptors to plug into the joystick.
You will need to provide connections for 'ground' and 'power' - to power the device. The jury is out as to whether it should be 3.3V or 5V.
The other connections are the common SPI bus lines: MISO, MOSI and SCK and the Select wire needs to be connected to a digital I/O used to select the device.
The grey wire is optional depending on whether you want to use the rumble motors. If you want to use them then connect it to an unregulated supply voltage between 7.2v and 9v.
You can of course add as many controllers as you like - each controller requires its own unique Select pin but otherwise the connections are the same for every controller.
When sharing the hardware SPI bus with an ISP programmer it is recommended that you add a pull up resistor on the Select line of the controller so that it doesn't interfere with the programmer when programming. Alternatively: only have either the controller or the programmer plugged in at any one time. If you are programming via a bootloader then this doesn't apply.
NB The controller is slightly flakey - so, for now, only use a software SPI bus as the hardware bus seems to work too fast for the controller.
In Project Designer you must must add the controller to an existing SPI Bus.
If you wish to use the joysticks then you must place the controller into analog mode. This gives access to both the left and right joysticks as well as virtual joysticks using the D-pad buttons on the left and the shape buttons on the right.
Each joystick has two values: X and Y.
Here is an example for the Axon and Axon II assuming you have called it 'controller' in Project Designer:-
//In appInitSoftware we will calibrate the controller
In our main loop we read the controller:-
    // We can now test the buttons
    // and the joysticks
Function Summary

Valid XHTML 1.0 Transitional