So whenever I use the arduino examples for the button example that uses IF/else the light will either be dim and brighten up or just stay dim. I've tried 2 arduinos (an Uno and a mega 2560) and I get the same thing on both.
Any help would be greatly appreciated as I am at a standstill on learning this stuff.
Are you talking about the File->Examples->02.Digital->Button example that goes with this tutorial:
?
johnwasser:
Are you talking about the File->Examples->02.Digital->Button example that goes with this tutorial:
http://www.arduino.cc/en/Tutorial/Button
?
Yes, that is what I'm talking about
Try ignoring that wiring method.
Connect one leg of the switch to ground. Connect the other leg to the digital pin you want to use. Change INPUT to INPUT_PULLUP.
Then, LOW will mean pressed and HIGH will mean released.
How are you wiring the LED?
I agree with @PaulS that it would be better to use the internal pullup resistor.
However I just tried the standard sketch on my Mega wired in accordance with the instructions and it works fine.
I can't help feeling you have a wiring error.
...R
Note that on that same tutorial page near the bottom, there are several more links that have the same circuit.
Debounce - read a pushbutton filtering noise
Button State Change - counting the number of button pushes
The Button State Change sketch could indicate how noisy or stable your push button switch is.
The Debounce sketch could be used to filter (ignore) any noise.
The wiring method PaulS has suggested is a more common approach.
Note that a 4-pin tactile switch has 4 pins only for mechanical mounting. Pairs of the pins are shorted together so if you get the switch rotated 90° it will not work as expected.