Matrix Keypad - Optimisation

Now that you are scrutinizing my code as I should be, I guess I will;

I notice a few other problems below;

I changed the keypressed values and in doing so noticed I had an extra argument (17 possible keys)

if (keyboardValue <25){keypressed = 0;}

this range is actually in the while statement at the very beginning so that if it is less than 25 it does nothing until something is pressed.

am I right to want to exclude this range from void readkeyboard? or do I want to define a state in there from 0-25 as a keypressed state?

it wouldn't make sense to me as no key is actually pressed and that while statement seems to take care of that......I think

in the code below I fixed the errors you mentioned and removed that keypressed state of <25

and made the first keypressed range 25 - 68

if (keyboardValue >=25) && (keyboardValue <68){keypressed = 1;}

As shown above I also forgot a pair of parentheses on both sides of the keyboardValue statements which while not correct below, I did fix in my code; I noticed it after beginning this message.

this is the statement I speak of that I think excludes the values below 25, but i don't completely understand it.

keyboardValue = analogRead(keyboardPin); // read the keyboard value (0 - 1023)
while (keyboardValue < 25){
//do nothing until a key is pressed
keyboardValue = analogRead(keyboardPin);
delay(50);
}//end of do nothing till a key is pressed

I began this with the code from a 3x4 matrix, and never verified it beforehand but, as I understand the code, it's supposed to be telling it to do nothing. I don't get how it is accomplishing that. it seems to me, that it is telling it the value is whatever it reads on the analog pin.

int keypressed = 0;
int keyboardPin = 0; // Analog input pin that the keypad is attached to
int keyboardValue = 0; // value read from the keyboard

void setup(){

Serial.begin(9600); //hardware serial to PC

}

void loop(){

keyboardValue = analogRead(keyboardPin); // read the keyboard value (0 - 1023)
while (keyboardValue < 25){
//do nothing until a key is pressed
keyboardValue = analogRead(keyboardPin);
delay(50);
}//end of do nothing till a key is pressed

readkeyboard(); //get the value of key being pressed "keypressed" i.e. 0-9

}

//read the keyboard routine
void readkeyboard(){
keyboardValue = analogRead(keyboardPin); // read the value (0-1023)
if (keyboardValue >=25) && (keyboardValue <68){keypressed = 1;}
if (keyboardValue >=68) && (keyboardValue < 108)){keypressed = 2;}
if (keyboardValue >=108) && (keyboardValue < 153)){keypressed = 3;}
if (keyboardValue >=153) && (keyboardValue < 186)){keypressed = 4;}
if ((keyboardValue >=186) && (keyboardValue < 254)){keypressed = 5;}
if ((keyboardValue >=254) && (keyboardValue < 361)){keypressed = 6;}
if ((keyboardValue >=361) && (keyboardValue < 457)){keypressed = 7;}
if ((keyboardValue >=457) && (keyboardValue < 525)){keypressed = 8;}
if ((keyboardValue >=525) && (keyboardValue < 621)){keypressed = 9;}
if ((keyboardValue >=621) && (keyboardValue < 738)){keypressed = 10;}
if ((keyboardValue >=738) && (keyboardValue < 812)){keypressed = 11;}
if ((keyboardValue >=812) && (keyboardValue < 854)){keypressed = 12;}
if ((keyboardValue >=854) && (keyboardValue < 898)){keypressed = 13;}
if ((keyboardValue >=898) && (keyboardValue < 945)){keypressed = 14;}
if ((keyboardValue >=945) && (keyboardValue < 970)){keypressed = 15;}
if (keyboardValue >=970){keypressed = 16;}
//NOTE: the values used above are all halfway between the value obtained with each keypress in previous test sketch

while (keyboardValue > 68) {
delay (100);
keyboardValue = analogRead(keyboardPin); // read the value (0-1023)
}//wait until key no longer being pressed before continuing

Serial.println(keypressed); // print the value back to the Serial view window on your PC
delay(1000); // wait 1000 milliseconds before the next loop
}
//end of read the keyboard routine

Thanks again for all your patience and direction. I couldn't imagine trying to figure this all out on my own.

-carl