Thanks for all the replies ![]()
I have spend some time getting info from each one of the messages and have a working code that does what it is meant to do. I took into consideration NO_Key, which return nothing when the user press ' F ' with no inputs in the buffer.
Working code
/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>
char key;
char buffer[7];
int i;
const byte ROWS = 2; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'A','B','C'},
{'D','E','F'}
};
byte rowPins[ROWS] = {9,8 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
i = 0;
buffer[0] = '\0';
while( i < sizeof(buffer) - 1)
{
key = getChar();
if (key == 'F')
{
break;
}
else if ( key != NO_KEY)
{
buffer[i] = key;
i++;
buffer[i]= '\0';
}
}
Serial.println(buffer);
}
char getChar()
{
char key = customKeypad.getKey();
if (key != NO_KEY)
{
return key;
}
else {
return NO_KEY;
}
}
Screenshot of Serial Monitor

Image of setup

Thanks again to all the replies.