Hi everyone,
Thank you all for your kindly replies. Yesterday I finally get my first step, use the code involved here:http://www.dfrobot.com/wiki/index.php?title=DFRduino_RoMeo and finally the motor moves,(although only one moves, I’m still learning and fixing it).
The code involved in that link is as follows:
Sample 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
///For previous Romeo, please use these pins.
int E1 = 6; //M1 Speed Control
int E2 = 9; //M2 Speed Control
int M1 = 7; //M1 Direction Control
int M2 = 8; //M1 Direction Control
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance(char a,char b) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (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=6;i<=9;i++)
pinMode(i, OUTPUT);
Serial.begin(19200); //Set Baud Rate
}
void loop(void)
{
char val = Serial.read();
if(val!=-1)
{
switch(val)
{
case 'w'://Move Forward
advance (100,100); //PWM Speed Control
break;
case 's'://Move Backward
back_off (100,100);
break;
case 'a'://Turn Left
turn_L (100,100);
break;
case 'd'://Turn Right
turn_R (100,100);
break;
}
delay(40);
}
else stop();
}
What I used are a Duemilanove Arduino, a Romeo, a 4wd robot and of course batteries. But the problem is :
1.The code above controls only two motors, when I control four motors, where should I change?
2.As you can see, there are many switch-case in the loop method, but I never used that before,what does that mean?
For example, can I enter the word “w” to control the robot move forward? Where to enter? How can I write a java interface or web interface to control?
Thank you again for everyone’s help, in this place I really learned a lot. :*