Two press switches?

Hello, I have 4 LEDs and one press switch. The press switch changes the pattern of the LEDs. Could I add another one to change the pattern again? If so, please tell me how to do it.

Thanks. $)

Could I add another one to change the pattern again?

Yes, or you could even use the same switch to change the pattern again, and again, and again.......

Why not post your current code as a starting point ?

This is my code:

int swichState = 0;

void setup(){

pinMode (3 , OUTPUT); pinMode (4 , OUTPUT); pinMode (5 , OUTPUT); pinMode (6 , OUTPUT); pinMode (2 , INPUT);

}

void loop() {

swichState = digitalRead(2);

if (swichState == LOW){

digitalWrite (3 , HIGH); digitalWrite (4 , LOW); digitalWrite (5 , LOW); digitalWrite (6 , HIGH);

delay (900);

digitalWrite (3 , LOW); digitalWrite (4 , HIGH); digitalWrite (5 , HIGH); digitalWrite (6 , LOW);

delay (650); }

else{

digitalWrite (3 , LOW); digitalWrite (4 , LOW); digitalWrite (5 , LOW); digitalWrite (6 , HIGH);

delay (250);

digitalWrite (3 , LOW); digitalWrite (4 , LOW); digitalWrite (5 , HIGH); digitalWrite (6 , HIGH);

delay (250);

digitalWrite (3 , LOW); digitalWrite (4 , HIGH); digitalWrite (5 , HIGH); digitalWrite (6 , HIGH);

delay (250);

digitalWrite (3 , HIGH); digitalWrite (4 , HIGH); digitalWrite (5 , HIGH); digitalWrite (6 , HIGH);

delay (250);

digitalWrite (3 , LOW); digitalWrite (4 , LOW); digitalWrite (5 , LOW); digitalWrite (6 , LOW);

delay (250);

} }

Thanks for your reply! $)

Your code currently does something when the switch IS pressed, and something else when it isn't pressed.

Look at the state change detection example, to see how to do something when the switch BECOMES pressed, like increment a mode variable.

Then, lose the delays. They make your system completely unresponsive. The blink without delay example is a good one to study. Also, do some research on state machines.

OK, you posted your current code but it is a shame that you did not put it in code tags as requested in http://forum.arduino.cc/index.php?topic=97455.0

That aside, the program as it stands outputs the first pattern when the first switch is pressed or held and the second pattern when it is not pressed or held. Assuming that you want 3 patterns to be show like this

switch 1 closed and switch 2 open : pattern 1 switch 1 open and switch 2 closed : pattern 2 switch 1 open and switch 2 open : pattern 3

You need to add a second switch to the circuit and read its state then then do this

if (switchState1 == HIGH && switchState2 == LOW)
  {
    //code for pattern 1
  }
else if (switchState1 == LOW && switchState2 == HIGH)
  {
    //code for pattern 2
  }
else
  {
    //code for pattern 3
  }

Suggestions Name the input pins to make the code easier to read. const byte switchPin1 = 2; Use pull up or pull down resistors on the input pins or use

pinMode(switchPin1, INPUT_PULLUP);

Note that as written the program will not be very responsive to switch inputs because of the use of the delay() function which prevents the switch inputs being read during the delay(). There are ways round this but get the basics working first.