Your MRK-1 robot has 2 (left, right) motors, that can be instructed to go forward, reverse and in increments of speed. To express this in our sketch we use a number between -255 and 255 (full-reverse, full-forward). You will need to include (Arduino IDE menu “Sketch” –> “Include Library”) the Motor.h library to your Arduino sketch in order for this code to work. If this library is not available (installed) then use the installation instructions for the motors and pitches libraries in the Robotics item on the main TechLabs Reference Library Page.
In this template, the motors will turn on, and both will go full-forward for 2 seconds; then the left motor will go full-reverse, while the right motor stays full-forward for 1.26 seconds. This loop will repeat indefinitely.
#include “Motor.h”
// Motor pins
#define rightMotorSpeed 10
#define rightMotorDirection 8
#define leftMotorSpeed 9
#define leftMotorDirection 4
// Create our motor object
Motor motor;
void setup() {
// put your setup code here, to run once:
// Motor setup
motor.setupRight(rightMotorSpeed, rightMotorDirection);
motor.setupLeft(leftMotorSpeed, leftMotorDirection);
}
void loop() {
// put your main code here, to run repeatedly:
// start our turn, 1 = left, 2 = right
motor.left(255);
motor.right(255);
delay(2000);
motor.left(-255);
motor.right(255);
delay(1260);
}