Created
June 14, 2015 11:06
-
-
Save gregorykelleher/49a6182ea3e1087f861e to your computer and use it in GitHub Desktop.
SN754410 motor driver
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 motor1A = 9; // H-bridge (pin 2, 1A) | |
const int motor2A = 8; // H-bridge (pin 7, 2A) | |
const int motor3A = 13; // H-bridge (pin 14, 3A) | |
const int motor4A = 12; // H-bridge (pin 10, 4A) | |
const int enablePin1 = 10; // H-bridge enable pin | |
const int enablePin2 = 11; // H-bridge enable pin | |
const int pushButtonUp = 4; //initialise pushbutton pins | |
const int pushButtonDown = 5; | |
const int pushButtonLeft = 6; | |
const int pushButtonRight = 3; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(motor1A, OUTPUT); //set motor logic pins for each motor | |
pinMode(motor2A, OUTPUT); | |
pinMode(motor3A, OUTPUT); | |
pinMode(motor4A, OUTPUT); | |
pinMode(enablePin1, OUTPUT); //set enable pins for each motor | |
pinMode(enablePin2, OUTPUT); | |
pinMode(pushButtonLeft, INPUT); | |
digitalWrite(pushButtonLeft, HIGH); | |
pinMode(pushButtonRight, INPUT); | |
digitalWrite(pushButtonRight, HIGH); | |
} | |
void loop() { | |
if (digitalRead(pushButtonLeft) == LOW){ | |
digitalWrite(enablePin1, HIGH); | |
digitalWrite(enablePin2, HIGH); | |
digitalWrite(motor1A, HIGH); | |
digitalWrite(motor2A, LOW); | |
digitalWrite(motor3A, LOW); | |
digitalWrite(motor4A, HIGH); | |
Serial.println("left"); | |
} | |
else if (digitalRead(pushButtonRight) == LOW){ | |
digitalWrite(enablePin1, HIGH); | |
digitalWrite(enablePin2, HIGH); | |
digitalWrite(motor1A, LOW); | |
digitalWrite(motor2A, HIGH); | |
digitalWrite(motor3A, HIGH); | |
digitalWrite(motor4A, LOW); | |
Serial.println("right"); | |
} | |
else { | |
digitalWrite(enablePin1, HIGH); | |
digitalWrite(enablePin2, HIGH); | |
digitalWrite(motor1A, HIGH); | |
digitalWrite(motor2A, HIGH); | |
digitalWrite(motor3A, HIGH); | |
digitalWrite(motor4A, HIGH); | |
Serial.println("nothing"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment