Button that increments a counter #include &lt;Adafruit_RGBLCDShield.h&gt;
#include &lt;utility/Adafruit_MCP23017.h&gt;
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(0,0);

}

void loop() {
  uint8_t buttons = lcd.readButtons();
  int a;  
  if (buttons) {

    lcd.clear();
    lcd.setCursor(0,0);

    if (buttons &amp; BUTTON_UP) {
      a+= 1;
      lcd.setCursor(0,0);
      lcd.print(a);
    }
  }


I am trying to make a counter that increments everytime the button UP is pressed. Currently, all it is doing is printing 1 everytime the button is pressed. Any help would be nice! Thanks!
Your code, simplified, is:

void loop()
    int a;
    a += 1;
}


The problem here is that, by putting the declaration of your counter variable within the loop() function, you've made it local to that function. Every time loop() is called, a new variable a is created, initialized to zero, and then incremented.

You want to move the declaration outside of loop(), creating a global variable that will remain in existence and maintain its value after loop() exits, so that the value is still there when loop() is called again:

int a = 0;
void loop() {
    a += 1;
}


(This could also be done with a static variable, but that's probably beyond the scope of this question.)