Hey guys I have a arduino motor shield from adafruit and I want a code for it so that i can control two motors from it. So please could you post a code for it. Also could you tell me that can I connect 2 servos and 2 motors on the shield at one time without having any problem.
However the site does not tell that how can i control ‘2’ motors simultaneously. So I would like to have a code for controlling 2 motors simultaneously - First both ahead, then one forward and one behind, then both the other way and at last both backward.
I’m not sure what you mean by simultaneously, all code is executed inline, one instruction at a time. It does it so fast though, you might think that the commands are simultaneous.
Here is some function code for 4 motors I use in some of my robots.
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm AF_DCMotor motor2(2, MOTOR12_64KHZ); // motor #2 AF_DCMotor motor3(3, MOTOR12_64KHZ); // motor #3 AF_DCMotor motor4(4, MOTOR12_64KHZ); // motor #4