Help coding a push button to reverse direction with a potentiometer

Perhaps in Reply #18 I should have said to connect the common pin to GND. It depends on the construction of the switch whether that is actually the pin that is in the middle of the switch.

...R

well I've wired up the switch and messed around with the code but the switch seems to have either no effect (in all 3 positions) or it shuts down the motor completely(in all 3 positions). Currently, the switch is wired to A1 and A2 pins and the GND(next to pin 13). all of the functions work independently so something is either wrong with the if statement or the wiring. Can anyone tell me where I am going wrong?

would it be more appropriate to start a new thread since the topic has changed?

mamassingale:
would it be more appropriate to start a new thread since the topic has changed?

No. It makes more sense IMHO to keep all the info in one place.

Post the code you have been trying and a photo of a simple pencil drawing showing how you have everything connected. See this Simple Image Guide

...R

The code is posted in #19. Ill work on the diagram. Thanks!

here is a pencil drawing of the circuit

In this code (from Reply #19) you don't have any code to read the state of the pins and update switchPinAVal etc

void loop() {

if (switchPinAVal == HIGH && switchPinBVal == LOW)
{
  motorRunClockwise();
}
if (switchPinAVal == LOW && switchPinBVal == HIGH)
{
  motorRunAntiClockwise();
}
 else
 {
  digitalWrite(stepPin, LOW); // stop the motor
 }
  

}

...R

So by setting int switchPinVals = digitalRead(A1 and A2), I thought I was telling the Arduino to read pins A1 and A2 every time I call the variable switchPinVal. so I thought the first line would look like this:

if (digitalRead(A1) == HIGH) && digitalRead(A2) == LOW)
{
turn the motor clockwise
}

Is this not the case?

mamassingale:
Is this not the case?

No.

The code in Reply #19 just reads the switch values once in setup() where is is probably not much use.

These lines should be in loop()

  switchPinAVal = digitalRead(A1);
  switchPinBVal = digitalRead(A2);

...R