title: Arduino button counter
body: <p>I was using Arduino but I encountered problems with my code. I want a button to illuminate certain lights, and every time you press it, the lights will illuminate in a different pattern. Right now, the code does not keep track of how many times the button has been pressed. I would really appreciate any help!</p>
  
  <pre><code>const int buttonPin = 4;  // pushbutton 1 pin
  int ledPins[] = {5,6,7,8,9,10};
  int buttonCounter = 0;  
  int buttonState = digitalRead(buttonPin);
  
  void setup(){
    pinMode(buttonPin, INPUT); 
    Serial.begin(9600); 
    // The for loop refers to each pin number
    // by their position in the array
    for(int i = 0; i &lt; 6; i++){
      pinMode(ledPins[i], OUTPUT);
    }
  }
  
   int countButtonPresses() 
   {
     if (buttonState == 0) 
     {
       buttonCounter = buttonCounter + 1;
     }
     return buttonCounter;
   }
  
  void loop(){
    int displayTime = 800;
    int pattern = countButtonPresses();
    Serial.println(pattern);
    switch(pattern) {
      case 1: 
        for(int i = 0; i &lt;=5; i++){
          digitalWrite(ledPins[i], HIGH);
          delay(displayTime);
          digitalWrite(ledPins[i], LOW);
        }
        break;
      case 2:
        for(int i = 0; i &lt;=5; i += 2){
          digitalWrite(ledPins[i], HIGH);
          delay(displayTime); 
          digitalWrite(ledPins[i], LOW);
        }
        break;
      default:
        Serial.println(countButtonPresses());
    }
  }
  </code></pre>