Hi people
i am designing some code so that i can control my nitro rc car with a ps3 controller because the remote controller and reciver broke that came with it so im trying this
i am going to use a arduino uno with a usb host shield with a bluetooth dongle then two xbees two control the throttle servo and steering servo the xs in the code represent the numbers that i dont know yet.
//Program to run Two servos on a nitro rc car this is just a basic setup for now but i am wanting to add support to run xbees becasue the bluetooth
//does not have enough range to control the rc car. i dont know whether this is correct feel free to fix up my mistakes.
#include <PS3BT.h>
#include <Servo.h>
Servo Steer; // Create servo object for steering
Servo Throttle; // 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()
{
Steer.attach(1); // Attaches the servo on pin 1 to the servo object
Throttle.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(LeftHatX);
val.2 = PS3.getAnalogHat(RightHatY);
val.1 = map(val.1, x, 0, 179);
val.2 = map(val.2, x, 0, 179);
Steer.write(val.1);
Throttle.write(val.2);
if(Ps3.disconnect)
(
Steer.write(pos = 90) // This is so if the car drops out of range it wont keep going and crash
Throttle.write(pos = 0) // Same as above
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.