HOLD function in the keypad.h library

Hello everyone,

this is my first post here, and I'll do my best to provide with my problem as best as possible to see if I could get some help.
The problem I have is with the HOLD function in the keypad.h library, as stated in the subject.

The following piece of code is a small part of my bigger code, but it's the only piece that I can't get to work.
My bigger program is using the keypad.h library, and can be turned off and on.
Now, as soon as I've shut down my device, I wish to turn it on again with this piece of code.
The problem is that the hold function doesn't seem to work.

void turnSystemOn()
{
  char key = kpd.getKey();
  switch(kpd.getState())
      {
      case HOLD:
      if(key == '8'){Serial.println("Power ON."); systemPower = true; break;}
      }
}

I've tried a couple of things, but the HOLD function doesn't seem to want to go to work. If I check till where the code is running, it just quits at "HOLD". I changed it to PRESSED as well, and then it's working fine. It's just that when it loops through it, it only sees the button I pressed once, and then turns it down again.

Maybe someone has had the same problem and knows how to work this out?
Adios! And lots of thanks already.

It makes little sense to have a case statement with only one case in it. What do you do if the state is something else ?

The problem I have is with the HOLD function in the keypad.h library,

The "HOLD" in your code is presumably #defined somewhere to be a particular int value, not a function.

Ah, you're probably right. Before posting this piece of code I modified it slightly so it wouldn't seem too messy :stuck_out_tongue:
I've just started coding, and everything I do looks as if a monkey threw random characters at my screen :stuck_out_tongue:

Let's rewrite it a bit:

void turnSystemOn()
{
  char key = kpd.getKey();
  switch(kpd.getState() == HOLD)
      {
      if(key == '8'){Serial.println("Power ON."); systemPower = true; break;}
      }
}

Also, while writing this I didn't keep in mind that "function" often means different things.
The kpd.getState() returns one of the four states that a button can be in (PRESSED, HOLD, RELEASED and IDLE).
So, if you push a button, it'll return PRESSED. My code essentially does that.
However, there is a setHoldTime(unsigned int time), that should turn the PRESSED state to HOLD when the setHoldTime has passed. My code, for some reason, doesn't want to do that.

I'm sorry for my messy explanations. Since this is more or less my first week of coding I can't really do better yet.

For more information on the keypad.h Library, see: Arduino Playground - Keypad Library

  switch(kpd.getState() == HOLD)

So, you are switching on the values true and false.

      {
      if(key == '8'){Serial.println("Power ON."); systemPower = true; break;}
      }

And providing no case statements for either of those values. You REALLY need to understand the purpose of switch and the purpose of if. They are NOT the same purpose, though they are closely related.

everything I do looks as if a monkey threw random characters at my screen

Enroll in a C class, so that you don't look (or think) like a monkey.