Pages: [1]   Go Down
Author Topic: Keypad  (Read 451 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Getting one digit from the keypad is easy, but how do you get two or three digits from the user (through the keypad) and use it to do something useful.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You read the keypad as many times as you need. Either a fixed number of times, or until a terminating character is entered. As keys are read, you store them, or add them together, in whatever way is appropriate. When you have a complete entry, act on it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You just need to keep track of the number you are creating from the input. Every time you get a new input, multiply this by ten and add the new input to it. It's hard to create a solid example without more specifics, but something like the following should work:

Code:
int number = 0;

while( <more_input_required> )
{
  number *= 10;
  number += get_input();
}

Of course, you'll need to replace <more_input_required> with your own condition (no. of digits expected etc.) and replace get_input() with whatever function you call to get the next input.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46017
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can someone give me some feedback on what I am doing wrong.
Sure. It's pretty simple, really. You have a Serial.begin() statement, but no Serial.print() statements, to tell what is happening.

Code:
  keypad.getKey();
The getKey() method returns a value. If you are not going to use the value, it makes no sense to call the method.

Some things to care about. Is the keypadEvent() function ever called? In that function, the event is not the same as the key. An event is like keyPressed (a key was pressed) or keyReleased (the key is no longer pressed). The password class is concerned about characters, not events.

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24321
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought these all looked fairly similar, so I merged them.
Logged

"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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought these all looked fairly similar, so I merged them.

I thought I was reading up this post and then ... smiley

I think the event is not actually interrupt driven as I learned from a recent post. The event is called every time getKey is called so it's a callback function (right?).

Not sure about the password library at all. Why do people use it instead of strcpy is beyond me. I do strcpy strcmp. It's simple.
« Last Edit: April 18, 2012, 01:11:15 pm by liudr » Logged


Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46017
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not sure about the password library at all. Why do people use it instead of strcpy is beyond me. I do strcpy. It's simple.
strcpy()? Or strcmp()?

The password class hides the complexity (?) of defining and initializing the array, adding the new character to the end of the array, and comparing the contents of the array against a predefined string.
Logged

Pages: [1]   Go Up
Jump to: