beeing hestistant with information will rise the time needed for finding a solution.
post a description of what your code does when pressing every single key of your keypad.
attach a handdrawn picture of how you wired your keypad. Writing
I connect my keypad to 2-9
is not sufficient.
For analysing what is going on you should code a even more simpler program
if (keypad.isPressed('1')){[color=#222222][/color]
Serial.println(".");[color=#222222][/color]
}
means only if the function isKeypressed('1') returns true print a dot.
the keypad-library has a lot more functions.
what do you get for results if you just let print the value of the key?
DId you run some ready to use demo-programs? What where the results of these demo-programs?
replace your setup and loop functions with this ones
This program enable to check if the serial connection works at all
by printing Setup Start
and it will print the value of the key received
enclosed in hashtags # #
to make even visible if the received value is printable or not.
isPressed() is one of the library functions used to test whether multiple keys are pressed at the same time. If that is not what you are trying to do then the functions functions designed to detect a single keypress should be used
For everyone who asked. Yes, I need keypad.isPressed function.
My goal is to check if key is pressed or not. Of course, keypad.getKey can do this partially. However, it works only for one key and it detects only pressing a button, but not holding (which is my main goal).
As I said before, keypad.isPressed function does work for me. (Constantly returns false)
So, I you know how use it correctly or a different method for this, please reply this port.
Thanks.
byte Keypad::getState(char keyChar) {
for (byte i=0; i<LIST_MAX; i++) {
if ( key[i].kchar == keyChar ) {
if ( key[i].stateChanged )
return int(key[i].kstate);
}
}
return 0;
}
Edit keywords.txt (at line 21)
isPressed KEYWORD2
Replace with
getState KEYWORD2
In result, we get keypad.getState function which will return IDLE / PRESSED / HOLD / RELEASED (0, 1, 2, 3) constants.
Here's quick example for using our new function:
#include <Keypad.h>
const byte colPins[4] {5, 4, 3, 2};
const byte rowPins[4] {9, 8, 7, 6}; // or any other pins you connect your keypad to
Keypad pad = Keypad( makeKeymap("123A456B789C*0#D"), rowPins, colPins, 4, 4);
// char that we are testing
const char test = '#';
// usage of IDLE state
const bool usingIDLE = false;
byte state = 0;
void setup() {
Serial.begin(9600);
Serial.print("Key states for ");
Serial.print(test);
Serial.println(":");
if (usingIDLE) Serial.println("State: IDLE");
};
void loop() {
if (pad.getKeys()) {
state = pad.getState(test);
if (usingIDLE || state) Serial.print("State: ");
switch (state) {
case 0:
if (usingIDLE) Serial.println("IDLE");
break;
case 1:
Serial.println("PRESSED");
break;
case 2:
Serial.println("HOLD");
break;
case 3:
Serial.println("RELEASED");
break;
};
};
};
I hope you will find this helpful but anyways, thanks for your all replies.
Yes, but it only works for PRESSED state of button. So, I won't know if the button has already been released or still held. Thanks anyway, because after debugging I came up with some patches to the code that works perfectly for me.