Hello,
Currently Im trying to use the an old wireless ps2 controller to maneuver a small wheeled robot. Using the example code suplied with the library I can conclude the controller and all connections work PERFECT. However, when I attempted to write my own code everything started to go haywire and I am becoming baffled. All I want todo is take the value output from one of the joysticks and save it into a variable, yet when ever I attempt todo so the variables value is always 10. Here is an example of a simple code I wrote to give an example of where my problems arise.
#include <PS2X_lib.h> //for v1.6
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
int motorSpeed = 0;
void setup(){
Serial.begin(9600);
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
error = ps2x.config_gamepad(13,11,10,12, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
}
void loop(){
ps2x.read_gamepad(false, vibrate);
motorSpeed = (ps2x.Analog(PSS_RY), DEC);
Serial.print(motorSpeed);
delay(50);
}
that code will ALWAYS print out a value of 10 while this code will always print out the correct value.
#include <PS2X_lib.h> //for v1.6
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
int motorSpeed = 0;
void setup(){
Serial.begin(9600);
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
error = ps2x.config_gamepad(13,11,10,12, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
}
void loop(){
ps2x.read_gamepad(false, vibrate);
Serialprint(ps2x.Analog(PSS_RY), DEC);
delay(50);
}]
the ONLY differance is that I tried to save the value into a variable before sending it over serial. I am aware this is probably some stupid mistake I and do apologize in advance! However thanks for any help.