Push button doesn't response well.

Hello, I am trying to control a motor with 4 push buttons.
button 3 and 4 are working completely well.
but button 1 and 2 are sometimes not working with first next press.
it need to be pressed twice to move motor again.
Any idea what it’s problem is?

#define dSTART_POINT 0 //Start Position
#define dEND_POINT 20000 // Target Position
#define dDELAY_FAST 25 // Min Delay Value
#define dDELAY_SLOW	100 // Max Delay Value
#define dSWITCH_PIN_1	8 //Button one
#define dSWITCH_PIN_2	9 //Button two
#define dSWITCH_PIN_3	10 //Button three
#define dSWITCH_PIN_4	11 //Button four

enum
{
eMOTOR_STOP = 0,
eMOTOR_RUN,
};

enum
{
eSWITCH_STATE_UP = 0, // normal state
eSWITCH_STATE_DOWN, // When it is pressed
};

int m_motorIndex = 0;//motor position
int m_motorDir = HIGH;//motor dir
int m_motorState = eMOTOR_STOP;//motor state
int m_switch1State = eSWITCH_STATE_UP; //button one state
int m_switch2State = eSWITCH_STATE_UP; //button two state
int m_switch3State = eSWITCH_STATE_UP; //button three state
int m_switch4State = eSWITCH_STATE_UP; //button four state
int m_motorDelay= dDELAY_SLOW; //motor delay

void setup() 
{ 
pinMode(6, OUTPUT); // Motor Dir
pinMode(5, OUTPUT); // Motor Step
pinMode(13, OUTPUT);
pinMode(dSWITCH_PIN_1, INPUT);
pinMode(dSWITCH_PIN_2, INPUT);
pinMode(dSWITCH_PIN_3, INPUT);
pinMode(dSWITCH_PIN_4, INPUT);
Serial.begin(9600);
digitalWrite(6, HIGH);
m_motorIndex = 0;
}






void moveMotor()
{
digitalWrite(5, HIGH);
delayMicroseconds(m_motorDelay);
digitalWrite(5, LOW);
delayMicroseconds(m_motorDelay);

if(m_motorDir == HIGH)
{m_motorIndex ++;}
else  
{
digitalWrite(13, HIGH);
m_motorIndex --;} 
}

// 1 CONDITION: DETACT MOTOR STATE AND RESPOSE
// 2 CONDITION: SOPEED CONTROLL
// 3 CONDITION: TRAP MOTOR IN MOVING AREA

void moterProc()

{
if(m_motorState == eMOTOR_STOP) {digitalWrite(5, LOW);}
else if(m_motorState == eMOTOR_RUN && m_motorIndex <= dEND_POINT && m_motorIndex >= dSTART_POINT)
{moveMotor();

if( (dEND_POINT - m_motorIndex) <= (dDELAY_SLOW - dDELAY_FAST)) // INCREASE SPEED
{
if(m_motorDelay < dDELAY_SLOW)
m_motorDelay +=2;
}
else if( (m_motorIndex - dSTART_POINT) <= (dDELAY_SLOW - dDELAY_FAST)) // REDUCE SPPED
{
if(m_motorDelay < dDELAY_SLOW)
m_motorDelay +=2;
}
else
{
if(m_motorDelay > dDELAY_FAST)
m_motorDelay -=2;
}
}
if(m_motorIndex >= dEND_POINT || m_motorIndex <= dSTART_POINT)
{
m_motorState = eMOTOR_STOP;
digitalWrite(5, LOW);
m_motorDelay = dDELAY_SLOW;
}
else
{
digitalWrite(13,LOW);
}
}






void pushSwitch1or2()
{
if( m_motorState == eMOTOR_RUN)
{
m_motorState = eMOTOR_STOP;
}



else if(m_motorState == eMOTOR_STOP && (m_motorIndex == dEND_POINT || m_motorIndex < 10000))
{
digitalWrite(6, HIGH);
m_motorDir = HIGH;
m_motorState = eMOTOR_RUN;
moveMotor();
}
else if(m_motorState == eMOTOR_STOP && (m_motorIndex == dSTART_POINT || m_motorIndex > 10000))
{
digitalWrite(6, LOW);
m_motorDir = LOW;
m_motorState = eMOTOR_RUN;
moveMotor();
}
}




void pushSwitch3()
{
 if(m_motorState == eMOTOR_STOP && (m_motorIndex == dEND_POINT || m_motorIndex > dSTART_POINT))
{
digitalWrite(6, LOW); //
m_motorDir = LOW;
moveMotor();
}



else 
{

m_motorState = eMOTOR_STOP; 
}
}

void pushSwitch4()
{
 if(m_motorState == eMOTOR_STOP && (m_motorIndex == dSTART_POINT || m_motorIndex < dEND_POINT))
{
digitalWrite(6, HIGH); //
m_motorDir = HIGH;
moveMotor();
}

else 
{
m_motorState = eMOTOR_STOP; 
}
}


void loop() 
{
//digitalWrite(6, HIGH); // Turn left
if (digitalRead(dSWITCH_PIN_1) == HIGH) //?? 1 ??? ?? ?
{
if(m_switch1State == eSWITCH_STATE_UP)
{
m_switch1State = eSWITCH_STATE_DOWN; //?? 1? ??? ?? ??? ??
pushSwitch1or2();
}
}




else if (digitalRead(dSWITCH_PIN_1) == LOW)

{

m_switch1State = eSWITCH_STATE_UP; //?? 1? ??? ?? ??? ??

}









if (digitalRead(dSWITCH_PIN_2) == HIGH)
{
if(m_switch2State == eSWITCH_STATE_UP)
{
m_switch2State = eSWITCH_STATE_DOWN; //?? 2? ??? ?? ??? ??
pushSwitch1or2();
}



}
else if (digitalRead(dSWITCH_PIN_2) == LOW)
{
m_switch2State = eSWITCH_STATE_UP;
}








if (digitalRead(dSWITCH_PIN_3) == HIGH)
{
  pushSwitch3();
}


else if (digitalRead(dSWITCH_PIN_3) == LOW)
{
if(m_switch3State == eSWITCH_STATE_DOWN)
{
m_switch3State = eSWITCH_STATE_UP;
m_motorState = eMOTOR_STOP;
}
}




if (digitalRead(dSWITCH_PIN_4) == HIGH)
{
  pushSwitch4();
}


else if (digitalRead(dSWITCH_PIN_4) == LOW)
{
if(m_switch3State == eSWITCH_STATE_DOWN)
{
m_switch3State = eSWITCH_STATE_UP;
m_motorState = eMOTOR_STOP;
}
}

moterProc();
}

I'm happy you put your code in code tags, but could you also format it too?

Anyway, it sounds to me like a debounce issue, but I can't be sure because the code is difficult to read.

Your not using the internal pullup resistors. Why not, I can not imagine. How ARE your switches wired?

When you press a button the contacts might vibrate a couple of milli seconds. Thus making it possible to either switch twice or more while you think you only press it once.

Here is an example to handle this : http://arduino.cc/en/Tutorial/Debounce

What I do is simply wait half a second and test if it is still pushed on. If so then the debounce has settled.