Control a LEGO NXT motor with arduino UNO

[center]I'm on a project in which i try to control a LEGO NXT motor with arduino UNO,i found many useful things in this forum-arduino site-playground e.t.c but lately i got a 'code' problem.In specific,i use the PID v1 library and use 2 interrupts for the sensors which work great BUT by the time i added a button with which i want to stop the motor at a position so as to calibrate it.[/center]
1st the motor doesn't completely stop and if it stops goes straight to the PID but it moves really slow.
2nd tried to use the do...while calibration example but things were worse.
For the Setpoint of the desired position of the motor i use a potentiometer connected on A0,mapped 0-180.I also used bigger delays again nothing.I only post the VOID loop cause i think you will understand the rest,if not i ll post the whole code.

i apologize if my post is bad but it's my 1st one,thanks in advance even if no one replies this forum has helped me a lot to do what i ve already done.Here's the code:
 void loop()
                    int reading = digitalRead(12);                 // read the state of the switch into a local variable:
                    if (reading != lastbuttonState1)               // check to see if you just pressed the button (i.e. the input went from LOW to HIGH),  and you've waited 
                                                                  // long enough since the last press to ignore any noise If the switch changed, due to noise or pressing:
                       lastDebounceTime = millis();              // reset the debouncing timer
                    if ((millis() - lastDebounceTime) > debounceDelay)     // whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
                      buttonstate1 = reading;
                  if (buttonstate1==0)              
                                         digitalWrite(motorPin0, 1);
                                         digitalWrite(motorPin1, 0);
                       {                digitalWrite(motorPin0, 1);
                                        digitalWrite(motorPin1, 1);

         lastbuttonState1 = reading;   // save the reading.  Next time through the loop,
                                                    // it'll be the lastButtonState:
             Setpoint = map(analogRead(A0), 0, 1023, 0, 180);
               if (Pwm1_val>=0)
               if (Pwm1_val<0)

Please read the guidelines and edit your post to use

// code tags for code