Skip to content

Instantly share code, notes, and snippets.

@battis
Created March 27, 2020 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/bd1c81520b10a8cbc0dd797af9972529 to your computer and use it in GitHub Desktop.
Save battis/bd1c81520b10a8cbc0dd797af9972529 to your computer and use it in GitHub Desktop.
const int ENABLE_A = 4;
const int ENABLE_B = 5;
const int SPEED = 6;
void setup() {
pinMode(ENABLE_A, OUTPUT);
pinMode(ENABLE_B, OUTPUT);
pinMode(SPEED, OUTPUT);
}
void brakeMotor(int milliseconds) {
digitalWrite(ENABLE_A, LOW);
digitalWrite(ENABLE_B, LOW);
analogWrite(SPEED, 0);
delay(milliseconds);
}
void runMotor(int speed, int milliseconds, int isA = true) {
if (isA) {
digitalWrite(ENABLE_A, HIGH);
digitalWrite(ENABLE_B, LOW);
} else {
digitalWrite(ENABLE_A, LOW);
digitalWrite(ENABLE_B, HIGH);
}
analogWrite(SPEED, speed);
delay(milliseconds);
}
void loop() {
runMotor(255, 100, true);
brakeMotor(100);
runMotor(255, 100, false);
brakeMotor(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment