Servo button

Hi guys, this is my first post, and i’m not the best with arduino yet. I’m trying to build a circuit which will turn on/off servo when the button is pressed. And i can’t get it to work at all at the moment. What am I doing wrong?

#include <Servo.h>

const int servoPin=8;
const int buttonPin=2;

int buttonState=0;
int directionState=0;

Servo myservo;
int pos=0;


void setup() {
  myservo.attach(8);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState=digitalRead(buttonPin);

  if(directionState == 0){
    if (buttonState=HIGH) {
      directionState=1;
      for(pos=0;pos<180;pos=pos+1){
    }
  }

}
else if(directionState==1){
  if(buttonState==HIGH){
    directionState=0;
    for(pos=180;pos>=1;pos=pos-1)
    {
      myservo.write(pos);
      delay(15);
    }
  }
}
}

if(directionState == 0){
    if (buttonState=HIGH)

One of these comparisons is wrong.

Can you tell us what that code should do ? Should it turn the servo by some angle after you press the button ? What is going wrong ? How we'll know whats wrong if you don't tell us ? Please check this-http://forum.arduino.cc/index.php?topic=52113.0

-Malhar

Servo should be turning an angle when the button is pressed, as I said earlier. My circuit is connected as you can see on attached picture. However, my circuit and / or code don't seem to be working together, and at the end I'm getting no reaction...

Have you fixed the code?
Why doesn’t the first conditional pair move the servo?

i can’t see what’s wrong with code, any suggestions?

Have another look at reply #1

AWOL: Have another look at reply #1

I looked at it again... still can't see what's wrong with it. Beginnings are so frustrating :(

either:

directionState == 0 or buttonState=HIGH

is NOT being set (correctly)

*usually = means assignment == means conditional check