I'm getting lost in the logic.
Hi mancow, if the keypad library is causing confusion, consider not using it! Here is a sketch that fires off continuous data to the serial monitor whenever a key is pressed. It does not use keypad.h or difficult logic. Try it out - maybe you can adapt it to your project.
The keypad map is easy to make. The top row is the leftmost pin connected to each other pin. If you get continuity on a pin combination, type the character there. If not, put a zero as a placeholder. The next row starts with the 2 pin on the left, and so on.
// 3x4 keypad plugged into Arduino using pins 2-8
// must add 2 to any variable that is a pin number!
int i, j;
char pad[][7] = {{ 0 ,'2', 0 ,'0', 0 ,'8','5'}, // keypad map
{ 0 , 0 ,'1', 0 ,'3', 0 , 0 },
{ 0 , 0 , 0 ,'*', 0 ,'7','4'},
{ 0 , 0 , 0 , 0 ,'#', 0 , 0 },
{ 0 , 0 , 0 , 0 , 0 ,'9','6'}};
void setup() {
Serial.begin(9600);
for(i=0; i<7; i++)
pinMode(i+2, OUTPUT);
}
void loop() {
for(j=0; j<5; j++) { // for first 5 pins
pinMode(j+2, OUTPUT); // set to output and
digitalWrite(j+2, LOW); // bring one pin LOW
for(i=j+1; i<7; i++) { // check pins to right
pinMode(i+2, INPUT_PULLUP); // which are held HIGH
delay(2); // allow time to detect
if(digitalRead(i+2)==LOW) { // if one is found LOW
Serial.println(pad[j][i]); // print key character
}
}
digitalWrite(j+2, HIGH); // bring pin back to HIGH
}
}