Pushbutton based led pattern changer

hello, i am making project based on pushbutton based led changer. means when i pressed push button,pattern 1 will execute, if i pressed second time ,pattern 2 will execute. i have code for that but problem is ,pattern is not execute in sequence.when i pressed first button it goes to pattern 1, again i prerssed button it goes to pattern 4 and so on.i want to make them in sequence

sketch_sep25b.ino (1.59 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

Here's OP's code:

int buttonPin = 2;  // pushbutton 1 pin
int LED1 = 3;
int LED2 = 4;
int LED3 = 5;

volatile int buttonCounter = 0;
int buttonState = 0;

void countButtonPresses();
void looping();

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  //Here is much better
  buttonState = digitalRead(buttonPin);

  //Attach interrupt to button pin
  attachInterrupt(0, countButtonPresses, FALLING);
}

void loop() {
  int displayTime = 800;
  Serial.println(buttonCounter);
  looping();
}

void countButtonPresses()
{
  buttonCounter = buttonCounter + 1;
  // modify this condition with number of patterns
  if (buttonCounter > 4) {
    buttonCounter = 1;
  }
}
void looping()
{
  switch (buttonCounter) {
    case 0:
      pattern1();
      break;
    case 1:
      pattern2();
      break;
    case 2:
      pattern3();
      break;
    case 3:
      pattern4();
      break;
  }

}
void pattern1() {
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
}
void pattern2() {
  digitalWrite(LED1, HIGH);
  delay(100);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED1, LOW);
  delay(100);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED2, LOW);
  delay(100);
  digitalWrite(LED3, LOW);
  delay(100);
}
void pattern3() {
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
}
void pattern4() {
  digitalWrite(LED1, HIGH);
  delay(100);
  //digitalWrite(LED2, HIGH);
  digitalWrite(LED1, LOW);
  delay(100);
  digitalWrite(LED3, HIGH);
  //digitalWrite(LED2, LOW);
  delay(100);
  digitalWrite(LED3, LOW);
  delay(100);
}