Hi! New to Arduino and psyched. However..I've been trying to do simple 'use a pushbutton to a LED' but I get this message when I press the button
Because a USB device was drawing too much power from your computer, one or more of your USB devices have been disabled.
To prevent damaging your computer, the USB device drawing too much power has been disabled. Other devices may have also been disabled...
Sounds like you've connected it so that the button shorts out the power supply! Could you post details of how you've connected everything together? A sketch or a photo would make it much easier for people to help you.
Yup, definitely wrong wiring. Connect one side of the switch to GND. Connect the other side of the switch to pin 7 (red wire). Get rid of the resistor and other yellow wire (to 5V).
^^^^^^^^^^
Or you can leave the code as is, and swap the wires for ground and signal. ust move the right yellow wire over, and the red wire to thw contact on the pushbutton.
Thanks Jeremy. Liked your suggestion but still can't get the light to go with the wires switched as you said (and the original code). Tried restarting program and computer just for good measure as well. Guess I'm a little stumped here..
I'm a bit confused about what you're trying to achieve. It looks like what you're wanting to do is have the LED change state on a button press, but what you've written won't achieve that. If you just want a simple "on while pressed" behavior, you could simplify your sketch to this (untested):
It may seem like the logic is inverted, but what's happening is that the internal pull-up on the BUTTON pin will hold that input high unless the button is pressed. So a LOW value on the button corresponds to a press, which is then used to set a HIGH value (illuminated) for the LED.
@PeteAJ: What Graynomad's suggestion does is set the LED output pin level to match the BUTTON input pin level. Very simple and clear.
The "!" you see in my trivially modified version is a logical "NOT" operator, which reverses the logic so that instead of setting the LED output to the same level as the BUTTON input, it sets it to the opposite value. Since the button is "low" while pressed that'll give the effect of turning on the LED when the button is pressed, and off when released.
Jon
Edit: Added in the second closing bracket that was missing from the copied / pasted code
Jon, Mike, Graynomad.. thanks for the input. I've tried your code versions and the code itself and the suggestions/mods make sense..
I'm new to this. Working on the second example in the Massimo's 'Getting Started with Arduino' book. Controlling an LED with a pushbutton.
I went back to my original setup with the second yellow and red wires flipped in relation to the resistor 'cause that got rid of my USB power warning error as per Jeremy's suggestion.
Replugged the USB
changed by LED ..just in case
Compile, save, upload in Arduino, and my LED still doesn't turn on.
The 2nd orange light on the Arduino board (marked L) responds to the button press (which must be a good sign).
This is only my second thing but not giving up until I figure this out.
Does it look like I have the right 10K ohm? There are 1K and 10K ones in the MakerShed starter kit and I wasn't completely convinced I'm telling them apart.