cool kart project

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.

Wizkid288:
but i donr know if this will work

I don't either. Perhaps you should try it and let us know.

Use CODE TAGS when posting code.

sorry im new ti this :drooling_face:

That is why there is a sticky at the very top : Read this before posting a programming question :wink:
You should try your code - nobody is going to do this for you :slight_smile: If you find anything wrong with it - then come back and write what is working and what is not.

well there is a problem. it says expected initializer before "." token on this line

int val.Ps3.getAnalogHat(RightHatY);

What is that line supposed to do?

read what is coming off the joystick on the ps3 controller

int val.Ps3.getAnalogHat(RightHatY);

There is no object named val, therefore, you can't use '.' to access any of it's members. You're also in the global scope, so there shouldn't be any "reading" going on, because you should only be declaring and initializing variables there. You need to change that line to declare a valid variable to store the values. Then, in your loop function, you need to do the reading and assign the value to the variable.

Thanks arrch but I don't really understand any of that so I don't know how to fix it. Or write the code in general.

Wizkid288:
Thanks arrch but I don't really understand any of that so I don't know how to fix it. Or write the code in general.

That's going to make it pretty difficult to do the project, then.

Ok we'll do you have any suggestions on where I can look to get the code or get an idea of what the code should look like?

Go through the example code, c++ tutorials, and references of the dot operator. Things that include the word"get" usually involve done sort of assignment statement. Probably another good thing to learn about.

ok thanks for all your help