Simple button function not working

origin example: http://arduino.cc/en/Tutorial/ButtonStateChange

I want to write a simple to use button function, so I don’t to use all those code every time. wrote it over and over again. Doesn’t work. Any tips?

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);

byte arrowUp[8] = {
  0b00100,
  0b01010,
  0b11011,
  0b00000,
  0b00100,
  0b01110,
  0b01010,
  0b01010
};

// Pinouts =====
int buttonPin[4]={
  A4,A3,A2,A1}; // Button 1-4
int ledPin[5]={
  8,9,10,11,12};   // Led 1-5

int maPin=A5;               
int tempPin=A6; 
int lightSenPin=A7;
int beeperPin=A0;
// Pinouts =====

int currentButtonState[4]={
  0,0,0,0};
int lastButtonState[4]={
  1,1,1,1};
    
int arrowCounter=0; //8 printed location counter  


void setup (){
  lcd.begin(16,2);
  lcd.createChar(1, arrowUp);

  for(int x=0; x<4; x++){
    pinMode (buttonPin[x], INPUT_PULLUP);
  }

  for(int x=0; x<5; x++){
    pinMode (ledPin[x], OUTPUT);
  }

}

/* Function usage
 menuSelector(0); //print arrow up on (0, 1)
 
 if(buttonState(0) == 1 ) // Button 1 has been pressed!
 */

void loop (){
  
  char debug [16];
  sprintf (debug, "%1d-%1d %1d %1d-%1d" , buttonState(0),buttonState(1),arrowCounter,  currentButtonState[0], currentButtonState[1]  );  
  lcdPrint(debug);

  int printLocation[8]= {
    0, 2, 4, 6, 8, 10, 12, 14  }; // 8 location where arrow up will be printed one by one when a button is pressed
  
  currentButtonState[0]=buttonState(0);
  if(currentButtonState[0]==0 && lastButtonState[0]==1 ){  // if button 1 is pressed
    arrowCounter++;         // pointer location changes by + one
    if(arrowCounter==8) arrowCounter=0; // 8 locations limit
  }
  
  currentButtonState[1]=buttonState(1);
  if(currentButtonState[1]==0 && lastButtonState[1]==1 ){  // if button 2 is pressed
    arrowCounter--;         // pointer location changes by - one
    if(arrowCounter==-1) arrowCounter=7; // 8 locations limit
  }  


  menuSelector(printLocation[arrowCounter]); //go ahead print the arrow

}


void menuSelector(int xLoc){                   // Lcd print arrowUp function 
  lcd.setCursor (xLoc, 1); 
  lcd.write (byte(1));
}


void lcdPrint(char* text){                   // Lcd print text function for debug
  lcd.setCursor (0, 0); 
  lcd.print( text );
}


boolean buttonState( int btpin){                // button function 
  boolean cbs= digitalRead(buttonPin[btpin]);
  if(cbs != lastButtonState[btpin]){
    if(cbs==LOW){
      lastButtonState[btpin]=cbs;  
      return cbs;
    }

  }
}

What's wrong with a simple buttonState = digitalRead(buttonPin);

If that doesn't work please explain why not so that a solution for the actual problem can be found.

...R

boolean buttonState( int btpin){                // button function 
  boolean cbs= digitalRead(buttonPin[btpin]);
  if(cbs != lastButtonState[btpin]){
    if(cbs==LOW){
      lastButtonState[btpin]=cbs;  
      return cbs;
    }

  }
}

This is crap. EVERY path through the code should return something. What does this function return if the pin state is the same as the last pin state? Garbage, that's what. Whatever was left in that memory location last time it was written to.

What is returned if the current state is different, but is not LOW? Garbage, again. Whatever was left in that memory location the last time it was written to.

You should NEVER write code like this.