//the program is supposed to run Two servos using the analog sticks on a ps3 controller using the Y axis.
//Using the Left analog stck with the Y axis on the ps3 controller to controll the Left servo.
//Using the Right analog stick with the Y axis on the ps3 controller to controll the Right servo.
#include <PS3BT.h>
#include <Servo.h>
Servo Left; // Create servo object for steering
Servo Right; // Create servo object for throttle
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will just create the instance
int val.1; // Variable to read Left analog stick of Ps3 controller
int val.2; // Variable to read Right analog stick of Ps3 controller
boolean printTemperature;
boolean printAngle;
void setup()
{
Left.attach(1); // Attaches the servo on pin 1 to the servo object
Right.attach(2); // Attaches the servo on pin 2 to the servo object
}
void loop()
{
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected)
{
val.1 = PS3.getAnalogHat(LeftHatY);
val.2 = PS3.getAnalogHat(RightHatY);
val.1 = map(val.1, x, 0, 179);
val.2 = map(val.2, x, 0, 179);
Left.write(val.1);
Right.write(val.2);
if(Ps3.disconnect)
(
Left.write(pos = 0) // This is so if the car drops out of range it wont keep going and crash
Right.write(pos = 0) // Same as above
}
i get the error "expected initializer before numeric constant" on this "int val.1;" part of the code. can any one help me thanks
Choose variable names that do not have a dot "." in them. You will still have separate variables for left and right in your code. It is just the "." that is the problem.
so for that part of the code it should look like this?
Servo Left; // Create servo object for steering
Servo Right; // Create servo object for throttle
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will just create the instance
int LeftYVal; //THE EDITED PART
int RightYVal; //THE EDITED PART
boolean printTemperature;
boolean printAngle;
//the program is supposed to run Two servos using the analog sticks on a ps3 controller using the Y axis.
//Using the Left analog stck with the Y axis on the ps3 controller to controll the Left servo.
//Using the Right analog stick with the Y axis on the ps3 controller to controll the Right servo.
#include <PS3BT.h>
#include <Servo.h>
Servo Left; // Create servo object for steering
Servo Right; // Create servo object for throttle
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will just create the instance
int LeftYVal; // Variable to read Left analog stick of Ps3 controller
int RightYVal; // Variable to read Right analog stick of Ps3 controller
boolean printTemperature;
boolean printAngle;
void setup()
{
Left.attach(1); // Attaches the servo on pin 1 to the servo object
Right.attach(2); // Attaches the servo on pin 2 to the servo object
}
void loop()
{
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected)
{
LeftYVal = PS3.getAnalogHat(LeftHatY);
RightYVal = PS3.getAnalogHat(RightHatY);
LeftYVal = map(LeftYVal, x, 0, 179);
RightYVal = map(RightYVal, x, 0, 179);
Left.write(LeftYVal);
Right.write(RightYVal);
if(Ps3.disconnect)
(
Left.write(pos = 0) // This is so if the car drops out of range it wont keep going and crash
Right.write(pos = 0) // Same as above
}
Because you haven't declared x anywhere. I think you should take a look at the reference for the map() function. It requires 5 arguments, and you're only passing it 3 plus a mystery one (x).
well im not sure ether all i want it to do is control one servo with one analog stick on the ps3 controller using the Y axis and control the other servo with the other analog stick on the ps3 controller using the Y axis. so if you can help me do that then you have helped me.
thanks but can you just tell me how to fix the errors in this code
//the program is supposed to run Two servos using the analog sticks on a ps3 controller using the Y axis.
//Using the Left analog stck with the Y axis on the ps3 controller to controll the Left servo.
//Using the Right analog stick with the Y axis on the ps3 controller to controll the Right servo.
#include <PS3BT.h>
#include <Servo.h>
Servo Left; // Create servo object for steering
Servo Right; // Create servo object for throttle
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will just create the instance
int LeftYVal; // Variable to read Left analog stick of Ps3 controller
int RightYVal; // Variable to read Right analog stick of Ps3 controller
boolean printTemperature;
boolean printAngle;
void setup()
{
Left.attach(1); // Attaches the servo on pin 1 to the servo object
Right.attach(2); // Attaches the servo on pin 2 to the servo object
}
void loop()
{
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected)
{
LeftYVal = PS3.getAnalogHat(LeftHatY);
RightYVal = PS3.getAnalogHat(RightHatY);
LeftYVal = map(LeftYVal, x, 0, 179);
RightYVal = map(RightYVal, x, 0, 179);
Left.write(LeftYVal);
Right.write(RightYVal);
if(Ps3.disconnect)
(
Left.write(pos = 0) // This is so if the car drops out of range it wont keep going and crash
Right.write(pos = 0) // Same as above
}
i get the error"x was not declared in scope" on this part of the code
//the program is supposed to run Two servos.
//Using the Left analog stck with the Y axis on the ps3 controller to controll the Left servo.
//Using the Right analog stick with the Y axis on the ps3 controller to controll the Right servo.
#include <PS3BT.h>
#include <Servo.h>
Servo Left; // Create servo object for steering
Servo Right; // Create servo object for throttle
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will just create the instance
int x;
int LeftVal;
int RightVal; //THE EDITED PART
boolean printTemperature;
boolean printAngle;
void setup()
{
Left.attach(1); // Attaches the servo on pin 1 to the servo object
Right.attach(2); // Attaches the servo on pin 2 to the servo object
}
void loop()
{
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected)
{
LeftVal = PS3.getAnalogHat(LeftHatY);
RightVal = PS3.getAnalogHat(RightHatY);
LeftVal = map(LeftVal, x, 0, 179);
RightVal = map(RightVal, x, 0, 179);
Left.write(val.1);
Right.write(val.2);
if(Ps3.disconnect)
(
Left.write(pos = 0) // This is so if the controller drops out of range it wont keep going
Right.write(pos = 0) // Same as above
}
and i added "x" because it told me to
and now i get the error "at this point in file" on this line
oh i get it now @Grumpy_Mike at first i didnt know what you where talking about but now i get it.
]code]
LeftVal = PS3.getAnalogHat(LeftHatY);
RightVal = PS3.getAnalogHat(RightHatY);
LeftVal = map(LeftVal, 0, 1023, 0, 179);
RightVal = map(RightVal, 0, 1023, 0, 179);
Left.write(LeftVal);
Right.write(RightVal);
see i fixed that but now i get the error "ps3 was not declared in scope"on this line