How do I do, If button is pressed twice

I'm using a button to control a servo and I'm trying to do if the button is pressed once it turns to 45 degrees and if the button is pressed twice within 2 seconds if goes back to 0 degrees. I have all the code set for the turns but I can't seem to figure out how to do the if the button is pressed twice part. plz help me.

Show us a good schematic & image of your circuit.
Posting images:
http://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your complete sketch between code tags
[code]Paste your sketch here[/code]

Don't have the circuit made at the moment

#include <Servo.h>           //allows me to use a servo

Servo myservo;            //creates the servo as an object that I can use in the code
int pos = 0;               //takes the servo position
int buttonstate = 0;        //variable for reading the buttons status
const int button = 13;            //makes button correlate with pin #13
void setup() {
  // put your setup code here, to run once:

  myservo.attach(9);                        // attach the servo called myservo to the digital pwn pin #9
  pinMode(button, INPUT);                    //makes button an input

}

void loop() {
  // put your main code here, to run repeatedly:

  buttonstate = digitalRead(button);                 //reads the state of the button value

  for (pos = 45; pos >= 0; pos += 5)     //goes from 0 degrees to 45 degrees in steps of 5 degrees

    if (buttonstate == HIGH)     //if button is pressed
    { myservo.write(pos);         //turn servo to new pos (position) 45
      delay(500);
    }


  buttonstate = digitalRead(button);

  for (pos = 0; pos <= 0; pos = +5)   //goes from 45 degrees to 0 degrees in steps of 5 degrees

    if (buttonstate == HIGH, delay(>2000), buttonstate == HIGH)        
//if button is on for more than 2 seconds

  { myservo.write(pos);
      delay(500)
    }



}

The following is imaginative, but as you have probably discovered, won't compile. Use of delay() is rarely a good idea.

   if (buttonstate == HIGH, delay(>2000), buttonstate == HIGH)

Most people choose to detect button press and release events by polling, with a variable to keep track of the last button state.

After the first detection, record the time in milliseconds, then detect another press and release. Then check to see if the elapsed time between those events is less than 2000 milliseconds. You might find this forum thread enlightening, but a little search will reveal other tutorials.

Time to do some research on how to read pushbuttons and use millis()! Start with the link I posted in reply #3, and for millis(), study this tutorial.

the pressing the button twice thing seemed a little too hard for me so I used a long press of the button as a replacement.

#include <Servo.h>           //allows me to use a servo

Servo myservo;            //creates the servo as an object that I can use in the code
const int lock_milli = 100;      //creates amt of milli sec needed to lock
const int unlock_milli = 2000;   //
int pressLength_milliSec;
int pos = 0;               //takes the servo position
int buttonstate = 0;        //variable for reading the buttons status
const int button = 13;            //makes button correlate with pin #13
void setup() {
  // put your setup code here, to run once:

  myservo.attach(9);               // attach the servo called myservo to the digital pwn pin #9
  pinMode(button, INPUT_PULLUP);                    //makes button an input

}

void loop() {
  // put your main code here, to run repeatedly:

  buttonstate = digitalRead(button); //reads the state of the button value

  while (buttonstate == LOW) {                   //if button is LOW(pressed) do stuff

    delay(100);                                            //after button is pressed for 100millisec
    pressLength_milliSec = pressLength_milliSec + 100;    //add 100 milli to the press length variable
  }


  for (pos = 45; pos >= 0; pos += 5);     //goes from 0 degrees to 45 degrees in steps of 5 degrees

  if (pressLength_milliSec >= unlock_milli)  //if button is pressed for over 2 seconds
    myservo.write(pos);         //turn servo to new pos (position) 45





  else if (pressLength_milliSec >= lock_milli)         //if button is pressed for under 2 seconds
  {
    for (pos = 0; pos <= 0; pos = +5);   //goes from 45 degrees to 0 degrees in steps of 5 degrees

    myservo.write(pos);                   //turn servo to new pos(position)
    delay(500);
  }

  pressLength_milliSec = 0;                 //resets press length variable

}

The following can't work, because buttonstate will never change in the while loop. If you enter the loop with buttonstate LOW, it will simply loop forever, and the Arduino will not respond.

while (buttonstate == LOW) {                   //if button is LOW(pressed) do stuff

    delay(100);                                            //after button is pressed for 100millisec
    pressLength_milliSec = pressLength_milliSec + 100;    //add 100 milli to the press length variable
  }

Try this instead, which uses the millis() function as it is intended to be used:

unsigned long start=millis();
while (digitalRead(button) == LOW); //if button down, wait for button release
unsigned long pressLength_millis = millis() - start; //calculate time button was down

Ok I put that in the code and I'll see if it works soon. Thanks for all the help!!