Sorry to start another Topic on this, but it get's really annoing. I simply cannot control the motor's direction.
I am using something like this : I will post it in the next message due to Forum rules.
I am inputting into the Serial Monitor the desired values but simply cannot make the motors (two motors) to spin in both directions (separately or both at the same time).
This is intended to be the control of a RC tank.
The source code is:
int dirA = 12;
int dirB = 13;
int speedA = 10;
int speedB = 11;
byte ad,bd,as,bs;
void setup() { //call this once at the beginning
pinMode (dirA, OUTPUT);
pinMode (dirB, OUTPUT);
pinMode (speedA, OUTPUT);
pinMode (speedB, OUTPUT);
Serial.begin(115200);
}
void loop() { //main loop
if (Serial.available() > 2) { //if there is anything on the serial port, read it
ad = Serial.read(); //val direction A
bd = Serial.read(); //val direction B
as = Serial.read(); //speed A
bs = Serial.read(); //speed B
Serial.println(ad,DEC);
Serial.println(bd,DEC);
Serial.println(as,DEC);
Serial.println(bs,DEC);
if(ad = 48) digitalWrite(dirA,LOW);
if(ad = 49) digitalWrite(dirA,HIGH);
if(bd = 48) digitalWrite(dirB,LOW);
if(bd = 49) digitalWrite(dirB,HIGH);
if(as >50) analogWrite(speedA,as);
else digitalWrite(speedA,LOW);
if (bs > 50) analogWrite(speedB,bs);
else digitalWrite(speedB,LOW);
ad=0;
bd=0;
as=0;
bs=0;
}
}
Can someone tell me if there is something wrong with the code? Or simply i have connected the wrong pins to the motors. I connected them to the 4 pins like in the picture.
Thank you in advantage!