Go Down

Topic: Keypad library, hold state? (Read 1 time) previous topic - next topic

permnoob

I just can't seem to use it. I have my keypad rigged up, and displaying it onto a LCD screen.  However I can't figure out how to use the hold function.  I want to jog some motors and stuff when a key is held, and stop when it's released, but for some reason the keypad never registers a "HOLD" state.  or I am using it wrong, here is my current attempt.  the 0xDD plays a beeping sound.  Ihad a while statement instead of IF, and once it started beeping it would never stop!  not sure if that was a function of the keypad or the LCD, so I went IF, since I figured just keep guessing till I get it right. with this code I do see the "in switch" line, but never get inside the if statment

Quote

  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  Serial1.write(key);
  {
    switch (key)
    {
      case '*':
        Serial1.print("in switch");
        if (kpd.getState()==HOLD){
          Serial1.print("in if");
          delay(500);
          Serial1.write(0xDD);
          Serial1.print("hold");
        }
        break;



I could use some guidance, I don't want to have to use a ON key and OFF key

wizdum

Just a WAG on my part, but that 500ms delay could be messing with the way the keypad library detects a "HOLD" state.
"Anyone who isn't confused really doesn't understand the situation."

Electronic props for Airsoft, paintball, and laser tag -> www.nightscapetech.com

permnoob


permnoob

ok, pulling the hold if statement out of the switch made it work, so it seems the .getKey() is like the serial buffer, in that reading it clears it.  so even tho the key is still held, the getKey returns?? null I guess, but getState does return HOLD.  Also the key states probably don't update till loop() can, well, loop.  which makes sense I guess?  I never understood how the keypad can work in the background, and I guess the short answer is "It can't"

damn me and over thinking things

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview