Created
March 27, 2020 12:22
-
-
Save battis/bd1c81520b10a8cbc0dd797af9972529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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