I'm building a RC bluetooth car powered by a Arduino UNO and a l298p motor driver shield. On the bluetooth side of the car I'm using the HM-10 BLE module and the RemoteXY app. The problem I'm having is that the shield doesn't power the motors the intended way: I have a slider that can output values from -100 to 100 (the slider is self-centering to position 0). If the value is above 0, the motors should turn clockwise, and the speed should be proportional to the slider position. If the value is below 0, the motors should turn counterclockwise. But when I run the code, all it does is to power the motors to the max when going forwards, and absolutely nothin backwards.
The code:
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL
#include <RemoteXY.h>
#include <Servo.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,3,0,0,0,34,0,10,24,0,
4,48,0,6,13,52,2,26,4,176,
51,26,52,13,2,26,1,0,72,5,
11,11,1,16,66,85,90,90,69,82,
0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t slider_1; // =-100..100 slider position
int8_t slider_2; // =-100..100 slider position
uint8_t button_1; // =1 if button pressed, else =0
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
int const ENA = 10; // speed motor A
int const INA = 12; // direction motor A
int const ENB = 11; // speed motor B
int const INB = 13; // direction motor B
Servo myservo;
void setup()
{
RemoteXY_Init ();
pinMode(ENA, OUTPUT); // set all the motor control pins to outputs
pinMode(ENB, OUTPUT);
pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
myservo.attach(9); // attach servo to pin 9
}
void loop()
{
RemoteXY_Handler ();
if(RemoteXY.slider_1 > 0) {
digitalWrite(ENA, HIGH);
analogWrite(INA, RemoteXY.slider_1);
digitalWrite(ENB, HIGH);
analogWrite(INB, RemoteXY.slider_1);
}
else if(RemoteXY.slider_1 < 0) {
digitalWrite(ENA, LOW);
analogWrite(INA, -RemoteXY.slider_1);
digitalWrite(ENB, LOW);
analogWrite(INB, -RemoteXY.slider_1);
}
else {
digitalWrite(ENA, LOW);
analogWrite(INA, 0);
digitalWrite(ENB, LOW);
analogWrite(INB, 0);
}
myservo.write((-RemoteXY.slider_2 + 100) - ((-RemoteXY.slider_2 + 100) / 10));
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
}
I don't know what the problem is, so I really need help on this one.