I'm trying to use the L293D H-bridge to get a motor to go in one direction when button one is pressed and in a different direction when button two is pressed. and then for the motor to not move when both or neither button is pressed. I tried using the arduino project book that i have that goes over a zeotrope but the programing is designed for a different use case. I've had a hard time figuring out how to code the program. I'm pretty new to coding in general and i really hope someone can help me. the sketch Ive written is as follows. thank you in advance.
int controlPin1 = 2;
int controlPin2 = 3;
int enablePin = 8;
int fSS = 4; //forewardSwitchState
int rSS = 5; //rearwardSwitchState
void setup() {
pinMode(fSS, INPUT);
pinMode(rSS, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
Serial.begin(9600);
}
void loop() {
if ((fSS == HIGH) and (rSS == LOW)) {
digitalWrite(enablePin, HIGH);
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
Serial.print("Foreward button pushed");
}
if ((rSS == HIGH) and (fSS ==LOW)) {
digitalWrite(enablePin, HIGH);
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
Serial.print("Rearward button pushed");
}
if ((rSS == HIGH) and (fSS == HIGH)) {
digitalWrite(enablePin, LOW);
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
Serial.print("Both buttons pushed '0'/ ");
}
if ((rSS == LOW) and (fSS == LOW)) {
digitalWrite(enablePin, LOW);
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
Serial.print("Neither button pushed -_-");
}
}