Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
There is a variation of the above with PSAB substituted for the PSB for some of the buttons that
allow the user to get input from how hard the buttons are pressed. For example PSAB_BLUE
measures the amount of pressure applied to the X-button. This is very cool but not necessary for the
needs of this project.
Circuit
Click on the image or here for a higher resolution image.
The Code
The sketch below can be downloaded from here: ROVPS2ControlTest1.ino
You can also download the PS2X library from the following webpage: A Collection of Arduino
Libraries Used in This Project.
/*
ROVPS2ControlTest1.ino
While the readings from the controller could be plopped straight into
the servo commands, variable will be used to hold the values so
that it will simulate the data packages that will be sent to the
ROV arduino over the serial eventually.
*/
int ForwardVal = 0; //Value read off the PS2 Right Stick up/down.
int YawLeftVal = 0; //Value read off the PS2 Right Stick left/right
int UpVal = 0; //Value read off the PS2 Left Stick up/down
int RollLeftVal = 0; // Value read off the PS2 Left Stick left/right
int CamPitch = 90; //Angle of the camera servo.
int upLraw = 0; //Variables to carry the actual raw data for the ESCs
int upRraw = 0;
int HLraw = 0;
int HRraw = 0;
void setup()
{
ps2x.config_gamepad(13,11,10,12, false, false);
//setup pins and settings: GamePad(clock, command, attention, data,
Pressures?, Rumble?)
//We have disabled the pressure sensitivity and rumble in this instance and
//we know the controller type so we have not bothered with the error checks
pinMode(grnLEDpin, OUTPUT); //Sets the grnLEDpin to output
pinMode(redLEDpin, OUTPUT); //Sets the redLEDpin to output
pinMode(yelLEDpin, OUTPUT); //Sets the yelLEDpin to output.
CamRec = false; //Sets the Camera default to not recording
UpLServo.attach(5);// attaches the Up left Servo to pin 5
UpRServo.attach(6);// attaches the Up Right Servo to pin 6
HorizLServo.attach(7);// attaches the Horizontal Left Servo to pin 7
HorizRServo.attach(8);// attaches the Horizontal Right Servo to pin 8
CamServo.attach(9); // Attaches the Camera Pitch Servo to pin 9.
void loop()
{
ps2x.read_gamepad(); //This needs to be called at least once a second
// to get data from the controller.
if(ps2x.Button(PSB_PAD_UP)) //Pressed and held
{
CamPitch = CamPitch + 1; //increase the camera pitch
}
if(ps2x.ButtonPressed(PSB_PAD_LEFT)) //Pressed
{
LEDHdlts = !LEDHdlts; //Toggle the LED light flag
}
UpLServo.write(upLraw);
UpRServo.write(upRraw);
HorizLServo.write(HLraw);
HorizRServo.write(HRraw);
if(CamPhotoInd >= 1)
{
CamPhotoInd = CamPhotoInd - 1; //countdown for the CamIndicator
digitalWrite(grnLEDpin,HIGH); //Light the Green LED to indicate
phototriggered
}
if(CamPhotoInd <= 0)
{
digitalWrite(grnLEDpin,LOW); //Photo event indication over.
}