Skip to content

Instantly share code, notes, and snippets.

@e70838
Created June 8, 2020 16:48
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 e70838/a4a8b9966ea54c44138b65ab42689777 to your computer and use it in GitHub Desktop.
Save e70838/a4a8b9966ea54c44138b65ab42689777 to your computer and use it in GitHub Desktop.
#define RightMotorEnable 9
#define RightMotorBackward 7
#define RightMotorForward 8
#define LeftMotorEnable 11
#define LeftMotorBackward 10
#define LeftMotorForward 12
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LeftMotorEnable, OUTPUT);
pinMode(LeftMotorForward, OUTPUT);
pinMode(LeftMotorBackward, OUTPUT);
pinMode(RightMotorEnable, OUTPUT);
pinMode(RightMotorForward, OUTPUT);
pinMode(RightMotorBackward, OUTPUT);
analogWrite(LeftMotorEnable, 255);
analogWrite(RightMotorEnable, 255);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
}
void loop() {
const int pin[4] = {LeftMotorForward, LeftMotorBackward, RightMotorForward, RightMotorBackward};
const int en[4] = {LeftMotorEnable, LeftMotorEnable, RightMotorEnable, RightMotorEnable};
for (int i = 0; i < 4; i++) {
analogWrite(en[i], 128); // slow speed
digitalWrite(pin[i], HIGH);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
analogWrite(en[i], 255); // full speed
delay(1000); // wait for a second
digitalWrite(pin[i], LOW);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment