Just to follow up on this I've now tested the library with V1.0.6 & V1.8.9 IDEs and in both version the first read code is correct.
I've pasted the test code below which is just a slightly cut down version of the example sketch. So if you're still seeing an issue with the sketch below then you can at least rule out the library as the cause.
#include <HCMatrixKeypad.h>
#define DEBOUNCE 10
#define PIN_C1 2 /* DIO for keypad column 1 */
#define PIN_C2 3 /* DIO for keypad column 2 */
#define PIN_C3 4 /* DIO for keypad column 3 */
#define PIN_C4 5 /* DIO for keypad column 4. Delete if there is no column 4! */
#define PIN_C5 6 /* DIO for keypad column 5. Delete if there is no column 5! */
#define PIN_C6 7 /* DIO for keypad column 6. Delete if there is no column 6! */
#define PIN_R1 12 /* DIO for keypad row 1 */
#define PIN_R2 11 /* DIO for keypad row 2. Delete if there is no row 2! */
#define PIN_R3 10 /* DIO for keypad row 3. Delete if there is no row 3! */
#define PIN_R4 9 /* DIO for keypad row 4. Delete if there is no row 4! */
#define PIN_R5 8 /* DIO for keypad row 5. Delete if there is no row 5! */
HCMatrixKeypad Keypad(DEBOUNCE, PIN_C1, PIN_C2, PIN_C3, PIN_C4, ROWMARKER, PIN_R1, PIN_R2, PIN_R3, PIN_R4); /* Uncomment for 4x4 keypad */
void setup()
{
Serial.begin(9600);
}
/* Main program */
void loop()
{
Keypad.Scan();
if(Keypad.New_Key())
{
Serial.println(Keypad.Read()); /* 10's column is the keypad row number */
}
}
It really does puzzle me though as to why with v1.06 I don't get the error. If a var is not initialised in v1.0.6 - the same would apply in v1.8.9.
It's just a guess. Usually when something is returning random values it either one of 3 things, an uninitialised variable, a physical issue (for instance something that should be connected that isn't, external rf noise, etc), or an array overrun.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.