Keypad/BCD Output

Hi, I am making a security system for my digital final project and only have the keypad left. I am able to set it up to have which key I pushed through the serial monitor but am having trouble outputting the key pressed in BCD(Binary Coded Decimal). Here is the code. Thanks to Ilya Brutman ilya@splitreaction.com. Sorry for the wall of text, not sure how shrink or put in seperate box like i seen others do.

int cols[] = {6,8,4};                                                                //set the pins that are connected to the columns on the keypad (order important)
int rows[] = {7,2,3,5};                                                              //set the pins that are connected to the rows on the keypad  (order important)
char labels[4][3] ={{'1','2','3'},{'4','5','6'},{'7','8','9'},{'*','0','#'}};        //define a label for each button

int ledPin = 13;// choose the pin for the LED
char bcd0 = 4;
char bcd1 = 6;
char bcd2 = 8;
char bcd3 = 12;
char temp;



void setup() {
  Serial.begin(9600);
  Serial.println("ready for action");

  pinMode(ledPin, OUTPUT);          // declare LED as output
  pinMode(cols[0], INPUT);          // declare column 0 pin as input
  pinMode(cols[1], INPUT);          // declare column 1 pin as input
  pinMode(cols[2], INPUT);          // declare column 2 pin as input
  pinMode(rows[0], OUTPUT);         // declare row 0 pin as output
  pinMode(rows[1], OUTPUT);         // declare row 1 pin as output
  pinMode(rows[2], OUTPUT);         // declare row 2 pin as output
  pinMode(rows[3], OUTPUT);         // declare row 3 pin as output
  pinMode(bcd0, OUTPUT);         // declare bcd0 pin as output
  pinMode(bcd1, OUTPUT);         // declare bcd1 pin as output
  pinMode(bcd2, OUTPUT);         // declare bcd2 pin as output
  pinMode(bcd3, OUTPUT);         // declare bcd3 pin as output

  digitalWrite(rows[0], HIGH);
  digitalWrite(rows[1], HIGH);
  digitalWrite(rows[2], HIGH);
  digitalWrite(rows[3], HIGH);
  digitalWrite(cols[0], HIGH);      //turn on pull up resisitor
  digitalWrite(cols[1], HIGH);      //turn on pull up resisitor
  digitalWrite(cols[2], HIGH);      //turn on pull up resisitor

}//setup





void loop(){

  temp = getButtonPress();    //check which button is currently pressed

  if (temp > 0){              //if a button is pressed
    Serial.print(temp);       //print it out
    Serial.print(" ");
  }

}//loop






char getButtonPress(){
  int val = 0;

  for(int j = 0; j<=2; j++){
    for(int i = 0; i<=3; i++){
        digitalWrite(rows[0], HIGH);       //set all the rows to HIGH
        digitalWrite(rows[1], HIGH);
        digitalWrite(rows[2], HIGH);
        digitalWrite(rows[3], HIGH);
        digitalWrite(rows[i], LOW);        //set the current row we are looking at to LOW

        val = digitalRead(cols[j]);        // read state of button at ROW i, Column j

        if (val == HIGH) {                 // check if the input is HIGH  (Button not pressed)
          digitalWrite(ledPin, LOW);       // turn LED OFF
        } else {
          digitalWrite(ledPin, HIGH);      // turn LED ON

              while(val == LOW){               // wait for button to be released
                delay(1);
                val = digitalRead(cols[j]);    // read input value
              }//while

              return(labels[i][j]);        //return the label of the button pressed
        }//if
    }//for i
  }//for j
  return 0;                        //return 0 if no button was pressed
}//getButtonPress

Sorry for the wall of text, not sure how shrink or put in seperate box like i seen others do.

Please modify your post. Select all the code, and press the button with the # symbol on it. It will add tags before and after the code that makes the forum software display it in a nice box.

but am having trouble outputting the key pressed in BCD(Binary Coded Decimal).

Output it to what?

  pinMode(cols[0], INPUT);          // declare column 0 pin as input
  pinMode(cols[1], INPUT);          // declare column 1 pin as input
  pinMode(cols[2], INPUT);          // declare column 2 pin as input
  pinMode(rows[0], OUTPUT);         // declare row 0 pin as output
  pinMode(rows[1], OUTPUT);         // declare row 1 pin as output
  pinMode(rows[2], OUTPUT);         // declare row 2 pin as output
  pinMode(rows[3], OUTPUT);         // declare row 3 pin as output

Hmm. Time for some reading: http://arduino.cc/en/Reference/For

I need to output the key selected to a 74147(decimal to bcd) which is then put into a shift register which is compared to another shift register... etc, etc. The security circuit is working. I currently have 2 dip switches in place of the keypad. It would be ideal to have 12 pins left to replace the dip switches directly but I only have 9 left after 7 are used for keypad, so i figured i could have it output the key i press in bcd, i convert that to decimal and feed that to the 74147. I cant feed the arduino directly to the 74147 because the key press also inhibits a clock pulse(NAND gates, any key goes low output a 1 to a one-shot)

Currently, your getButtonPress() function returns a character value from an array. Why not make it return an int value, and have the array contain the BCD value that you want to send when a particular key is pressed?