why is Led still on?

Hi,

i'm trying to code a NC Microswitch and led circuit/program.
My problem is that when the microswitch is close, it dips the led to ard 50% and when it's open it's brighter.
I'm using a duemilanove and Arduino 1.01.

any ideas?

int buttonPin = 2;     // the number of the pushbutton pin
int ledPin =  12;      // the number of the LED pin

// variables will change:
int buttonState = 1;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Perhaps describe your wiring in more detail.

I would suggest using the internal pull up resistor, and then connecting your switch between the input pin and ground. It eliminates the need for other components, although a 1K resistor in series may be a good idea.

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);   
  // initialize the pushbutton pin as an input, and activate the pull up resistor:
  pinMode(buttonPin, INPUT_PULLUP);     
}

Read this article for more info: http://arduino.cc/en/Tutorial/InputPullupSerial

dze:
My problem is that when the microswitch is close, it dips the led to ard 50% and when it's open it's brighter.

Which LED - the one you're trying to turn off? If so, it seems to me that the sketch is not doing anything like what you intend. Is your sketch detecting button presses correctly? Serial.println statements are your friend here.