Skip to content

Instantly share code, notes, and snippets.

@balexand
Created March 23, 2013 19:52
Show Gist options
  • Save balexand/5229130 to your computer and use it in GitHub Desktop.
Save balexand/5229130 to your computer and use it in GitHub Desktop.
Makes an Arduino robot pace back and forth.
int MOTOR_A_BRAKE = 9;
int MOTOR_A_SPEED = 3;
int MOTOR_A_DIR = 12;
int MOTOR_B_BRAKE = 8;
int MOTOR_B_SPEED = 11;
int MOTOR_B_DIR = 13;
void setup() {
pinMode(MOTOR_A_SPEED, OUTPUT);
pinMode(MOTOR_A_BRAKE, OUTPUT);
pinMode(MOTOR_A_DIR, OUTPUT);
pinMode(MOTOR_B_SPEED, OUTPUT);
pinMode(MOTOR_B_BRAKE, OUTPUT);
pinMode(MOTOR_B_DIR, OUTPUT);
digitalWrite(MOTOR_A_BRAKE, LOW); // disable the brake
digitalWrite(MOTOR_B_BRAKE, LOW); // disable the brake
digitalWrite(MOTOR_A_DIR, LOW); // move forward
digitalWrite(MOTOR_B_DIR, HIGH); // move forward
// note that you could also change the direction by screwing the motor wires in differently
}
// the loop routine runs over and over again forever:
void loop() {
analogWrite(MOTOR_A_SPEED, 255); // full speed
analogWrite(MOTOR_B_SPEED, 255); // full speed
delay(1000);
analogWrite(MOTOR_A_SPEED, 255); // keep going
analogWrite(MOTOR_B_SPEED, 0); // stop so the robot will turn
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment