// spin the left Motor CCW
leftMotor(-255);
delay(2000);
leftBrake();
delay(1000); // wait for 1000 milliseconds
// spin both motors (drive forward) -- left CW, right CCW
leftMotor(255);
rightMotor(-255);
delay(2000); // wait for 2000 milliseconds
leftBrake();
rightBrake();
// spin both motors (drive in reverse) -- left CCW, right CW
leftMotor(-255);
rightMotor(255);
delay(2000); // wait for 2000 milliseconds
leftBrake();
rightBrake();
}
/*******************
/ loop function
/*******************/
void loop()
{
// no code here. All driving code is in the setup() -- so that it runs just once.
}
/*******************************************************************************/
void leftMotor(int motorPower)
{
motorPower = constrain(motorPower, -255, 255); // constrain motorPower to -255 to +255
if(motorPower >= 0)
{
// spin CW
digitalWrite(L_CTRL1, HIGH);
digitalWrite(L_CTRL2, LOW);
analogWrite(L_PWM, abs(motorPower));
}
else
{
// spin CCW
digitalWrite(L_CTRL1, LOW);
digitalWrite(L_CTRL2, HIGH);
analogWrite(L_PWM, abs(motorPower));
}
}
/*******************************************************************************/
void leftBrake()
{
// setting both controls HIGH, shorts the motor out -- causing it to self brake.
Page 6 of 19
Need help?
Do you have a question about the RedBot and is the answer not in the manual?