HI. so im trying to make my ps3 controller controll 2 servos with the "RightHatY" and "LeftHatY" sofar i have this but i donr know if this will work
#include <PS3BT.h>
#include <Servo.h>
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
boolean printTemperature;
boolean printAngle;
Servo servo1; // create servo object to control a servo
Servo servo2; // create servo object to control a servo
int val.Ps3.getAnalogHat(RightHatY); // variable to read the value from the analog pin
int val.Ps3.getAnalogHat(LeftHatY); // variable to read the value from the analog pin
void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start BOO"));
while(1); //halt
servo1.attach(5); // attaches the servo on pin 5 to the servo object
servo2.attach(3); // attaches the servo on pin 3 to the servo object
}
Serial.print(F("\r\nPS3 Bluetooth Library Started YAY"));
}
void loop() {
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
Serial.print(F("\tRightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
Serial.print(PS3.getAnalogHat(RightHatY));
}
val = analogRead(RightHatY);
val = map(val, 0, 1023, 0, 254); // scale it to use it with the servo (value between 0 and 255)
servo1.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
val = analogRead(LeftHatY);
val = map(val, 0, 1023, 0, 254); // scale it to use it with the servo (value between 0 and 255)
servo2.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
}
}
thanks for the help in advance.