Skip to content

Instantly share code, notes, and snippets.

@tj-devel709
Created October 18, 2019 20:08
Show Gist options
  • Save tj-devel709/b4faada60776bf5eb81c9f2a44462fd6 to your computer and use it in GitHub Desktop.
Save tj-devel709/b4faada60776bf5eb81c9f2a44462fd6 to your computer and use it in GitHub Desktop.
Tech Team Arduino Motor Functionality
// Basic Motor Functionality based on truth tables at www.elegoo.com
// define IO pin
#define ENB 5
#define IN1 7
#define IN2 8
#define ENA 6
#define IN3 9
#define IN4 11
void setup() {
pinMode(IN1, OUTPUT); //set IO pin mode OUTPUT pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
//mian loop
void loop() {
motortest();
}
void motortest() {
forward();
delay(2000);
brake();
delay(1000);
right();
delay(1000);
pause();
delay(1000);
backward();
delay(2000);
pause();
delay(1000);
left();
delay(1000);
brake();
delay(10000);
}
void forward() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void right() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void backward() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void left() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void brake() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void pause() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment