Switch is not working

The switch is not working, it seems that the servo motor works itself before i open the switch, any help will be appreciated. Thanks. The code is as below:

int buttonPin = 8;

#include <Servo.h>

int servoPin = 9;

Servo servo;

int angle = 0; // servo position in degrees

int state=1;

int button =LOW;

boolean lastButton = LOW;

boolean currentButton = LOW;

long currentTime;

long previousTime;

void setup()

{

pinMode(buttonPin, INPUT);

servo.attach(servoPin);

}

boolean debounce (boolean last)

{

boolean current = digitalRead(buttonPin);

if (last != current)

{

delay(5);

current = digitalRead(buttonPin);

}

return current;

}

void loop() {

button = digitalRead(buttonPin); //normally open switch

currentTime = millis();

currentButton = debounce(lastButton);

if (lastButton ==LOW && currentButton == HIGH)

{

switch(state)

{

case 1 :

if (button == HIGH)

{

previousTime=currentTime;

state=2;

}

break;

case 2 :

if (currentTime - previousTime > 2000)

{

Liftup();

state=3;

}

break;

default:

break;

}

}

lastButton = currentButton;

}

void Liftup()

{

servo.write(-90);

}

Give us a break.

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

How to use this forum

That has to be the silliest way I have ever seen code posted. Bar none.

Did you even read your own post?

Alrighty. I am sorry since this is my first post. I will remake another forum. Thanks

Arg, not remake! Edit! It's digital, not paper....

y3nadruino:
Alrighty. I am sorry since this is my first post. I will remake another forum. Thanks

Bye.

Cross-posted here