/*
Problem 2: H-Bridge
An H-Bridge is a rudamentary method for controlling DC motors. You can find out more
about them here: https://en.wikipedia.org/wiki/H-bridge
On the right you'll see 3 buttons. The green (right) button is forward, the red (left) button is backward,
and the black (middle) button is stop. There is also a red and green LED in that order to indicate motor direction.
Your task is to write a program that simulates the action of an H-Bridge motor controller. This means,
in order to run the motor forward, you'll need to write HIGH on the forward pin and LOW on the backward
pin, and vice versa for reverse. When the motor is stopped, both pins should be LOW.
This should act like a momentary button. I.E. think about the radial arm saw. You push the button and
it runs until you hit the stop. Similarly, if I hit the green button the green LED should remain
on until I hit either the stop or reverse button. To do this, you'll want a 'direction' variable,
which I've included below.
*/
// elliot I really tried
#define FWD 2
#define BCK 3
#define FWD_BUTTON 8
#define BCK_BUTTON 10
#define STOP_BUTTON 9
int direction = 0;
int FWD_status = false;
int BCK_status = false;
int STOP_status = true;
void setup() {
pinMode(FWD, OUTPUT);
pinMode(BCK, OUTPUT);
pinMode(FWD_BUTTON, INPUT_PULLUP);
pinMode(BCK_BUTTON, INPUT_PULLUP);
pinMode(STOP_BUTTON, INPUT_PULLUP);
}
void loop() {
if (digitalRead(STOP_status) == true) {
STOP_status = !STOP_status;
direction = 0;
digitalWrite(FWD, !STOP_status);
digitalWrite(BCK, !STOP_status);
}
if (digitalRead(FWD_BUTTON) == true) {
FWD_status = !FWD_status;
direction = 1;
digitalWrite(FWD, FWD_status);
digitalWrite(BCK, !FWD_status);
}
while (digitalRead(FWD_BUTTON) == false);
delay(50);
if (digitalRead(BCK_BUTTON)== true) {
BCK_status = !BCK_status;
direction = -1;
digitalWrite(BCK, BCK_status);
digitalWrite(FWD, !BCK_status);
}
while (digitalRead(BCK_BUTTON) == true);
delay(50);
}
void forwardButton() {
}
void stopButton() {
}
void reverseButton() {
}