Hello,
I have bought a DFRobot Cherokey 4WD to connect to my Arduino mega 2560 and all commands are ok (backward, turn left, turn right) except forward (M1 HIGH and M2 HIGH at the same time).
Could you help me in resolving this trouble ?
Regards,
Frank
[code]int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
void stop(void) //Stop
{
digitalWrite(E1,0);
digitalWrite(M1,LOW);
digitalWrite(E2,0);
digitalWrite(M2,LOW);
}
void avance (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void recule (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void gauche (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void droite (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
Serial.begin(19200); //Set Baud Rate
Serial.println(“Run keyboard control”);
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void loop(void)
{
if(Serial.available()){
char val = Serial.read();
if(val != -1)
{
switch(val)
{
case ‘f’://Move Forward
avance (255,255); //move forward in max speed
break;
case ‘r’://Move Backward
recule (255,255); //move back in max speed
break;
case ‘g’://Turn Left
gauche (100,100);
break;
case ‘d’://Turn Right
droite (100,100);
break;
case ‘p’:
Serial.println(“Hello”);
break;
case ‘x’:
stop();
break;
}
}
else stop();
}
}[/code]