make buffer[] and i static.
get rid of the while() loop.
Like this:
int getTheNumber()
{
static char buffer[4];
static int i=0;
// Input up to 3 numbers until we find a * or #
char key = keypad.getKey();
// If it's a number AND we have space left, add to our string
if ('0' <= key && key <= '9' && i < 3)
{
buffer[i] = key;
i++;
return(-1)
}
// If it's a * or #, end
else if ('#' == key && i > 0)
{
// Null terminate
buffer[i] =0;
int value = atoi(buffer);
i=0;
return atoi(buffer);
}
}