Delay time for 180 spin on Mbot


#1

This is not a question, but it is a tip for everyone with an mbot. The delay required for the Mbot to do a perfect 180 (Not quite perfect, but nothing is) is 451.748. So to make the robot turn around, the code would look like this:

#include <MeMCore.h>

MeDCMotor motor1(M1); //Motor1 is Left Motor
MeDCMotor motor2(M2); //Motor2 is Right Motor

void setup(){
  delay(3000);
}

void loop()
{
  //motor.run() maximum speed is 255 to -255, 0 is stop
  motor1.run(-255);
  motor2.run(255);
  delay(451.748);

  motor1.stop();
  motor2.stop();
  delay(500);
}

The delay in the Setup is just to give me time to unplug it from my computer. A 360 spin is just 2 * a 180 spin, and a 90 degree turn is just half of this. In a longer program, I would probably set 451.5 as a variable and divide it and multiply it as necessary.

It will tend to decay over time, meaning that if you leave it in one place just spinning and stopping like this for a long period of time, it will start to be either just to little of a delay, or just too much.


#2