Go Down

Topic: Matrix keypad library not working Properly (Read 292 times) previous topic - next topic

khkarthik

In the below Program "Release" and "Idle" are not working...
i have connected all rows and columns correctly...

ANY HELP???????????????????????????




#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){

  // Fills kpd.key[] array with up-to 10 active keys.
  // Returns true if there are ANY active keys.
  if (kpd.getKeys())
  {
    for (int i=0; i<LIST_MAX; i++)   // Scan the entire list.
    {
      if (kpd.key.kchar != NO_KEY)    // Test for an active key.
      {
        switch (kpd.key.kstate) {  // Test for key state IDLE, PRESSED, HOLD, or RELEASED
            case HOLD:
                Serial.print("Key ");
                Serial.print(kpd.key.kchar);
                Serial.print(" is being HELD and the state ");
                if (!kpd.key.stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case PRESSED:
                Serial.print("Key ");
                Serial.print(kpd.key.kchar);
                Serial.print(" is PRESSED and the state ");
                if (!kpd.key.stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case RELEASED:
                Serial.print("Key ");
                Serial.print(kpd.key.kchar);
                Serial.print(" has been RELEASED and the state ");
                if (!kpd.key.stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            default:
                Serial.print("Key ");
                Serial.print(kpd.key.kchar);
                Serial.print(" is IDLE and the state ");
                if (!kpd.key.stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
        }
      }
    }
  }
}  // End loop

johnwasser


In the below Program "Release" and "Idle" are not working...

What, exactly, do you mean by 'not working'?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

khkarthik

I have connected the matrix key pad ...and when I press any key....I get the msg on my serial console as "pressed " and when I continue to hold ..I get the msg as "hold "...

but when I release the key...I'm not getting the " release " msg ...

I mean to say that ....in the switch case...the program is never entering the "release " and " idle " case...

I don't know wat could be the problem...either with the code which I've posted.. or with the keypad library ....

AWOL

You're likely to get better help if you observe these simple rules:

Don't cross-post (don't worry, I've deleted the duplicate of this one)

Don't SHOUT or allow your punctuation keys to auto-repeat...

Use code tags when posting code, so your code is legible.

it is all set out here - I'm really surprised you didn't see it.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johnwasser


I don't know wat could be the problem.


My first guess is:
Code: [Select]

  if (kpd.getKeys())
  {

Perhaps a Released key is not considered 'active' so this returns 'false'.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up