The reason i'm doing this in the first place is because there is NO lamp in my trunk. Instead of installing a plain light, I wanted to make an aesthetically pleasing LED arrangement to complement my subs. This is where I am. I think this should be working. I've got the LED hooked up to the GND and 13. I have a mommentary push button hooked up one end on the 5 volt spot, and the other on the #2 spot. This is what the code looks like.
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
It's really unpredictable now. It will work sometimes, and others it flicker or stay on and the button won't turn it off. Should the button be grounded? What's going on?