With ESP8266 I am having PCF 8574 with the code below for a general 4x4 keypad connectivity
#include "Wire.h"
#include "I2CKeyPad.h"
const uint8_t KEYPAD_ADDRESS = 0x20;
I2CKeyPad keyPad(KEYPAD_ADDRESS);
char keymap[19] = "123A456B789C*0#D";
#define DEBOUNCE_DELAY 200
unsigned long lastDebounceTime = 0;
int lastKey = -1; //
void setup()
{
Serial.begin(9600);
Serial.println(__FILE__);
Wire.begin();
Wire.setClock(400000);
if (keyPad.begin() == false)
{
Serial.println("\nERROR: cannot communicate to keypad.\nPlease reboot.\n");
while (1);
}
keyPad.loadKeyMap(keymap);
}
void loop()
{
if (keyPad.isPressed()) {
char ch = keyPad.getChar();
int key = keyPad.getLastKey();
unsigned long currentMillis = millis();
if (currentMillis - lastDebounceTime > DEBOUNCE_DELAY) {
if (key != lastKey) {
Serial.print(key);
Serial.print(" \t");
Serial.println(ch);
lastKey = key;
}
// Update the debounce timer
lastDebounceTime = currentMillis;
}
while (keyPad.isPressed()) ;
}
}
Now here I have numeric , alphabetic and special characters to assign like
if (ch==1) or if(ch==A) or if(ch==*) type thing from this pattern
123A
456B
789C
*0#D
Now suppose I want to replace keypad with a puch button network with same keypad configuration and same row column style
and I want to mention it as
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
And also I want to assign task in this numeric manner only:
if (ch==10) or if(ch==12) or if(ch==15) etc
Then how to define this char keymap[19] = "123A456B789C*0#D";
and how to assign after number 9 ??
Please guide !!!
xfpd
December 25, 2024, 5:42am
2
Those are conditions, not assignments.
Try a few practice sketches with a keypad. You will see the library determining the pressed key.
Have a look at the I2Ckeypad_keymap.ino example.
It shows how to get the mapped key from the library.
See line char ch = keyPad.getChar(); // note we want the translated char
There also it is given as :
char keymap[19] = "123A456B789C*0#DNF"; // N = NoKey, F = Fail
Up to now the last one I got is
char keymap[19] = "123A456B789C*0#DNF"; // N = NoKey, F = Fail
xfpd
January 6, 2025, 11:26pm
6
What is that line of code supposed to mean, and why did you bump your question twice?
Simply my aim is to get this
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
But I have no option left after 9
it is accepting as A,B,C,D,E,F IN PLACE OF 10,11,12,13,14,15,16
No idea for scripting the sequence from 1-16 directly !!
xfpd
January 6, 2025, 11:55pm
8
Strange to use 1 - 16 and not 0 - 15. Hexadecimal is a base 16 (0x10) counting system, not base 17.
You want someone to write it for you, as usual.
For the "1 - 16" system, when "key" is "A" key, substitute "10", for "B" substitute "11".... "F" will be "16
Tried it already but not working that way !
xfpd
January 7, 2025, 1:22am
10
King_RAJ_Enters:
Tried it already
No you did not. Had you tried it already, you would have stated so. You are not trying anything. All you are doing is demanding good people do your work, and you never appreciate the help.
King_RAJ_Enters:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
Have you run - I2Ckeypad_demo01.ino
It prints the index which is in the range 0, 1, ... 15, 16, 17
The value 16 means no key is pressed
The value 17 mean a failing read.
If you print Serial.println(index + 1)
you will get 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, 17 and 18
The latter two values are no key pressed and fail.
system
Closed
July 6, 2025, 10:45am
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.