Sono riuscito a controllare un joypad wireless della ps2.
Ho utilizzato questa libreria http://pspunch.com/pd/files/library/GPSX.zip
Questo è il programma
#include <GPSXClass.h>
#undef round
int asd =0;
void setup()
{
Serial.begin(9600);
PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_LOCK);
PSX.motorEnable(PSX_PAD1, MOTOR1_ENABLE, MOTOR2_ENABLE);
// Poll current state once.
PSX.updateState(PSX_PAD1);
}
void loop()
{
PSX.updateState(PSX_PAD1);
int data1 = ANALOG_RIGHT_X(PSX_PAD1);
int data2 = ANALOG_RIGHT_Y(PSX_PAD1);
int data3 = ANALOG_LEFT_X(PSX_PAD1);
int data4 = ANALOG_LEFT_Y(PSX_PAD1);
if (IS_DOWN_CIRCLE(PSX_PAD1)) {
PSX.motor(PSX_PAD1, MOTOR1_ON, ANALOG_RIGHT_X(PSX_PAD1));
}
if (PRESSED_CIRCLE(PSX_PAD1)) {
Serial.println("Pressed circle");
}
if (RELEASED_CIRCLE(PSX_PAD1)) {
Serial.println("Released circle");
PSX.motor(PSX_PAD1, MOTOR1_OFF, 0);
}
if (PRESSED_SQUARE(PSX_PAD1)) {
Serial.println("Pressed square");
PSX.mode(PSX_PAD1, MODE_DIGITAL, MODE_UNLOCK);
}
if (RELEASED_SQUARE(PSX_PAD1)) {
Serial.println("Released square");
}
if (PRESSED_CROSS(PSX_PAD1)) {
Serial.println("Pressed cross");
PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_UNLOCK);
PSX.motorEnable(PSX_PAD1, MOTOR1_ENABLE, MOTOR2_ENABLE);
}
if (RELEASED_CROSS(PSX_PAD1)) {
Serial.println("Released cross");
}
if (IS_DOWN_TRIANGLE(PSX_PAD1)) {
PSX.motor(PSX_PAD1,MOTOR1_ON ,ANALOG_LEFT_X(PSX_PAD1));
}
if (PRESSED_TRIANGLE(PSX_PAD1)) {
Serial.println("Pressed triangle");
}
if (RELEASED_TRIANGLE(PSX_PAD1)) {
Serial.println("Released triangle");
PSX.motor(PSX_PAD1, MOTOR1_OFF, 0x00);
}
if (PRESSED_UP(PSX_PAD1)) {
Serial.println("Pressed Up");
}
if (RELEASED_UP(PSX_PAD1)) {
Serial.println("Released Up");
}
if (PRESSED_DOWN(PSX_PAD1)) {
Serial.println("Pressed Down");
}
if (RELEASED_DOWN(PSX_PAD1)) {
Serial.println("Released Down");
}
if (PRESSED_LEFT(PSX_PAD1)) {
Serial.println("Pressed Left");
}
if (RELEASED_LEFT(PSX_PAD1)) {
Serial.println("Released Left");
}
if (PRESSED_RIGHT(PSX_PAD1)) {
Serial.println("Pressed Right");
}
if (RELEASED_RIGHT(PSX_PAD1)) {
Serial.println("Released Right");
}
if (PRESSED_CROSS(PSX_PAD1)) {
Serial.println("Pressed cross");
PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_UNLOCK);
PSX.motorEnable(PSX_PAD1, MOTOR1_ENABLE, MOTOR2_ENABLE);
}
if (RELEASED_CROSS(PSX_PAD1)) {
Serial.println("Released cross");
}
if (IS_DOWN_TRIANGLE(PSX_PAD1)) {
PSX.motor(PSX_PAD1, MOTOR1_ON, ANALOG_LEFT_X(PSX_PAD1));
}
if (PRESSED_TRIANGLE(PSX_PAD1)) {
Serial.println("Pressed triangle");
}
if (RELEASED_TRIANGLE(PSX_PAD1)) {
Serial.println("Released triangle");
PSX.motor(PSX_PAD1, MOTOR1_OFF, 0x00);
}
if (PRESSED_R2(PSX_PAD1)) Serial.println("Pressed R2");
if (RELEASED_R2(PSX_PAD1)) Serial.println("Released R2");
if (PRESSED_R1(PSX_PAD1)) Serial.println("Pressed R1");
if (RELEASED_R1(PSX_PAD1)) Serial.println("Released R1");
if (PRESSED_L2(PSX_PAD1)) Serial.println("Pressed L2");
if (RELEASED_L2(PSX_PAD1)) Serial.println("Released L2");
if (PRESSED_L1(PSX_PAD1)) Serial.println("Pressed L1");
if (RELEASED_L1(PSX_PAD1)) Serial.println("Released L1");
if (PRESSED_SELECT(PSX_PAD1)) Serial.println("Pressed Select");
if (RELEASED_SELECT(PSX_PAD1)) Serial.println("Released Select");
if(PRESSED_STICK_RIGHT(PSX_PAD1)){
Serial.println("analog right x= ");
Serial.println(data1);
Serial.println("analog right y= ");
Serial.println(data2);
}
if(RELEASED_STICK_RIGHT(PSX_PAD1)) Serial.println("Released Right Stick");
if(PRESSED_STICK_LEFT(PSX_PAD1)){
Serial.println("analog left x= ");
Serial.println(data3);
Serial.println("analog left y= ");
Serial.println(data4);
}
if(RELEASED_STICK_LEFT(PSX_PAD1)) Serial.println("Released Left Stick");
if(PRESSED_START(PSX_PAD1)){
Serial.println("analog right x= ");
Serial.println(data1);
Serial.println("analog right y= ");
Serial.println(data2);
Serial.println("analog left x= ");
Serial.println(data3);
Serial.println("analog left y= ");
Serial.println(data4);
}
if(RELEASED_START(PSX_PAD1)) Serial.println("Released Start");
}
ecco un video in cui tento di spiegare come funziona... spero che capiate tutto e che vi sia utile... è un po' tirato via a causa del fatto che non so editare video su linux