help a poor beginner
i have arduino romeo 1 elektro motor , ask if point me how can make code 2 motors requiered 1.what trying achieve when press on keyboard or d motor rotate left or right failed make work here sample code
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
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();
}
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
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();
}
does hardware work? in other words, have tried simple sketch spins motor 1 way, other?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help a poor beginner
arduino
Comments
Post a Comment