So in a roundabout way I have two potentiometers, and one motor. I'm running the PS3 bluetooth library on top of this. The DC motor is connected to a motor driver that is passing 12v through to the motor. My problem is that to be able to run the motor two directions at 12v clockwise and counter-clockwise, I need the 12v and ground signals that run into the motor to switch. Here's my 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;
BTD Btd(&Usb);
PS3BT PS3(&Btd);
#define MOT1pos 3
#define MOT1neg 5
void setup() {
pinMode(MOT1pos, OUTPUT);
pinMode(MOT1neg, OUTPUT);
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}
void loop() {
Usb.Task();
{
if (PS3.getAnalogButton(R2) > 0);
digitalWrite(MOT1neg, LOW);
analogWrite(MOT1pos, PS3.getAnalogButton(R2));
}
if (PS3.getAnalogButton(L2) > 0);
digitalWrite(MOT1pos, LOW);
analogWrite(MOT1neg, PS3.getAnalogButton(L2));
}
PS3.getAnalogButton(L2) and PS3.getAnalogButton(R2) are the potentiometers, and MOT1pos and MOT1neg are the motor leads. MOT1pos and neg are both going through the motor driver as well. When I try to drive the motor, both the ground and signal wires are outputting a signal, and I think this is because I'm trying to run a LOW signal through the motor driver. Any help would be greatly appreciated! XD
USEDIS.ino (754 Bytes)


