Hi guys using the simple BUTTON sketch found in our example library i would like to know how i can press the momentary switch and toggle between 2 pins and 2 ledsexample off statepressing the momentary switch on pin 2 would turn on led pin 13 and power up pin 12pressing the switch again would turn on led pin 11 and power up pin 10.press once more and goes back to off stateRegards James

What does 'power up' mean?i just mean it switches it on so i can hook up a relay to it after and use the led on pin 13 to know the state of the relay

Quote

LED attached from pin 13 to ground

Through a resistor, right?yes through a resistor

Nothing in your code has anything to do with pins 10,11, or 12 so you can't expect anything to happen on those pins. Is that the part you are needing help with?correct i would like to add that part of the code into the sketch.James

// 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 == HIGH) { Your comments are correct. Pay careful attention to what is happening, and, more importantly, what is NOT happening.

That code will do something when the switch is pressed. It doesn't matter if the switch was also pressed last time. If you want to toggle pins each time the switch is pressed, you do need to care if the switch was pressed last time, and only toggle the pin state when the switch state changes (to the pressed state).

You aren't using a button are you? Put it back on your shirt, and use a switch. Switches work a lot better.

One way to program for that would be to use a variable to keep track of how many times the momentary switch was depressed and to use switch / case (http://arduino.cc/en/Reference/SwitchCase) to control (turn on/power up) your output pins. After the count of three and your outputs have been turned off, reset the variable to zero.

Only very small relays can be driven directly from an Arduino pin; otherwise you sill need circuitry to drive the relay. If the relay is small enough to be directly driven with an Arduino pin you will have to connect a diode across the relay coil to protect the Arduino.