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);
}
}