Proximity Switch/DC Motor Control Issues HELP!

Hey everyone,

I am working on a relatively simple project but am having trouble with my code. I have two inductive proximity sensors acting as switches to control a large DC motor. The loop I need is simple: when proxy1 is tripped (detects a metal pin on the drive line) the motor starts in the forward direction until proxy2 is tripped. When proxy2 is tripped, pause for half a second, then go in reverse until proxy1 is tripped, then pause, go forward again, and so on. So far, the first part is working. When proxy1 is tripped, the motor starts up in the forward direction, but no response when proxy 2 is tripped, it just runs continuously.

To clarify part of the code, I am using a big MD30C R2 motor controller (no library required)
--> pwm = motor enabled pin
--> dir = direction pin (HIGH = forward, LOW = reverse)

Here is my code with notes:

const int proxyPin = 6; //proximity sensor 1
const int proxyPin2 = 7; //proximity sensor 2
const int pwm = 9; //pwm on motor control board (motor enable pin)
const int dir = 5; //direction pin on motor control board (HIGH = forward, LOW = reverse)

int proxyState = 0; // variable for reading proxy 1's status
int proxyState2 = 0; //variable for reading proxy 2's status

void setup() {
//outputs:
pinMode(pwm, OUTPUT);
pinMode(dir, OUTPUT);
//inputs:
pinMode(proxyPin, INPUT);
pinMode(proxyPin2, INPUT);
}

void loop() {
// read the state of the switch values:
proxyState = digitalRead(proxyPin);
proxyState2 = digitalRead(proxyPin2);

// check if the first switch is triggered.
if (proxyState == HIGH) //remember proxy pins are pulled HIGH to begin and go LOW when triggered
{
digitalWrite(pwm, LOW); //the motor is off
}
if (proxyState == LOW) { //if proxy 1 is triggered
digitalWrite(pwm, HIGH); //turn the motor on
digitalWrite(dir, HIGH); //in the forward direction

while(digitalRead(proxyState2) == HIGH){ //**this section is the problem
digitalWrite(pwm, HIGH); //keep motor on until proxy2 is triggered
digitalWrite(dir, HIGH);
}
}
if(proxyState2 == LOW) //**not working
{
digitalWrite(pwm, LOW); //when proxy2 is tripped, pause, then reverse until proxy1 is triggered
delay(500);
digitalWrite(pwm, HIGH);
digitalWrite(dir, LOW);

while(digitalRead(proxyState) == HIGH); //**not working
digitalWrite(pwm, HIGH); //continue in reverse until proxy1 is triggered, the pause, and go forward again, etc...
digitalWrite(dir, LOW);
}
}

Any help would be greatly appreciated, I assume the solution is simple but it has eluded me so far!

while(digitalRead(proxyState2) == HIGH){ //**this

Read again. proxystate? or proxypin ?

Ha! It was that simple... Thank you. Now the next step is adding a button so that when the button is pressed, the motor cycles until the opposite proximity switch is triggered, then stops.