Hi all,
I'm starting a new build, a 3 servo hexapod. I have arduino uno, usb shield, ps3 controller, BT dongle, mini servos etc.
I have the ps3 controller successfully talking to the uno and can run the PS3BT sketch no problem.
I can run the servos in a forward loop with or without the controller connected.
My question is, How do I stop it from moving?
Here is my code. I don't think the controller is doing anything at the moment?. I have commented out the other movements for now, until I can get the basics working.
#include <PS3BT.h> //Include the necessary libraries.
#include <Servo.h>
USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
Servo servoCenter; //Define center servo
void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
servoLeft.attach(3); // Set left servo to digital pin 3
servoRight.attach(5);
servoCenter.attach(6); // Set right servo to digital pin 6
}
void loop() { // Loop through motion tests
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.getAnalogHat(RightHatX) >145);
{forward();} // Example: move forward
if(PS3.getAnalogHat(RightHatX) <=135);
{stopRobot();}
}
}
// Motion routines for forward
void forward() {
servoCenter.write(50);
delay(250);
servoRight.write(160);
servoLeft.write(10);
delay(250);
servoCenter.write(120);
delay(250);
servoRight.write(10);
servoLeft.write(160);
delay(250);
}
void stopRobot() {
servoLeft.write(90);
servoRight.write(90);
servoCenter.write(90);
}