const int leftFrontDirection = 28; const int leftRearDirection = 26; const int rightFrontDirection = 24; const int rightRearDirection = 22; const int leftFrontSpeed = 13; const int leftRearSpeed = 12; const int rightFrontSpeed = 11; const int rightRearSpeed = 10; const int stop = 0; // the next 4 numbers are for example only const int slow = 85; const int medium = 170; const int fast = 255; const int forward = 1; const int reverse = 0; void setup() { pinMode ( leftFrontDirection, OUTPUT ); pinMode ( leftRearDirection , OUTPUT ); pinMode ( rightFrontDirection , OUTPUT ); pinMode ( rightRearDirection , OUTPUT ); pinMode ( leftFrontSpeed , OUTPUT ); pinMode ( leftRearSpeed , OUTPUT ); pinMode ( rightFrontSpeed , OUTPUT ); pinMode ( rightRearSpeed , OUTPUT ); } void loop() { //move forward slow for 1 sec move(forward, forward, slow); delay(1000); //move forward medium for 1 sec move(forward, forward, medium); delay(1000); //reverse fast for 1 sec move(reverse, reverse, fast); delay(1000); } void move(int leftDirection, int rightDirection, int speed) { digitalWrite( leftFrontDirection, leftDirection ); digitalWrite( leftRearDirection, leftDirection ); digitalWrite( rightFrontDirection, rightDirection ); digitalWrite( rightRearDirection, rightDirection ); analogWrite( leftFrontSpeed, speed ); analogWrite( leftRearSpeed, speed ); analogWrite( rightFrontSpeed, speed ); analogWrite( rightRearSpeed, speed ); }