Hi guys I'm relatively new to Arduino and new to this form! Any help you can offer me would be greatly appreciated!
So I'm making a bluetooth controlled robot with a sainsmart motor bridge, USB 2.0 host, bluetooth dongle, PS3 controller, and etc. I think you get the general idea. Anyways I got all the circuitry and stuff up and running but I'm having trouble with the code. I've been teaching myself to code with this so I'm not exactly the best haha.
Anyway here is my problem: I'm just trying to get this thing working on a simple test to run one motor when I press the X button on the PS3 controller. I got it working BUT it doesn't stop when I let go -_-
Any ideas what's wrong?
Here is the code:
#include <PS3BT.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
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;
//VARIABLES
int enableA = 3;
int enableB = 6;
int IN1 = 1;
int IN2 = 2;
int IN3 = 4;
int IN4 = 5;
void setup(){
Serial.begin(115200);
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
pinMode(enableA, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop(){
Usb.Task();
if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.getButtonClick(CROSS) == HIGH){
delay(10);
analogWrite(enableA, 255);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
if (PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS3.disconnect();
}
}
}
Thanks in advance!