Pages: [1]   Go Down
Author Topic: Start with keypad and password  (Read 1584 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello. i'm working on project with simple keypad (just like this http://arduino.cc/playground/uploads/Main/16buttonkeypad.jpg). I'm trying to do like that: enter correct password which turn blue led on. If password incorrect turn red led on. From where should I start?

Thanks for answering.

Simas
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Start with the exercises on the tutorial site - http://www.arduino.cc/en/Tutorial/HomePage - to get a general understanding of how the Arduino can be programmed.

After that you can go to the playground articles.

- http://www.arduino.cc/playground/Code/Keypad
- http://www.arduino.cc/playground/Main/KeypadTutorial

All this could be easily found with the search option in the upper right corner.

Succes,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

I read everything before and used and example and then I got and and error on row  -  Keypad keypad = Keypad(rowPins,colPins,rows,cols);

An error: PasswordKeypad:25: error: no matching function for call to 'Keypad::Keypad(byte [4], byte [4], byte&, byte&)'
C:\Users\Simas\Desktop\Arduino\libraries\Keypad/Keypad.h:63: note: candidates are: Keypad::Keypad(char*, byte*, byte*, byte, byte)
C:\Users\Simas\Desktop\Arduino\libraries\Keypad/Keypad.h:57: note:                 Keypad::Keypad(const Keypad&)



/*
||
|| @file PasswordKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | A simple password application that uses a keypad as input source.
|| #
||
*/

//http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Password.h>
//http://www.arduino.cc/playground/uploads/Code/Keypad.zip
#include <Keypad.h>

Password password = Password( "1234" );

byte rows = 4; //four rows
byte cols = 4; //four columns
byte rowPins[] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[] = {6,7,8,9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(rowPins,colPins,rows,cols);

const byte ledPin = 13;

void setup(){
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  digitalWrite(ledPin, HIGH);   // sets the LED on
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
 
void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset(); break;
   default:
      password.append(eKey);
  }
}


void guessPassword(){
   if (password.evaluate()){
      digitalWrite(ledPin,HIGH);
   }else{
      digitalWrite(ledPin,LOW);
   }
}






What's wrong?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need this one:
Quote
note: candidates are: Keypad::Keypad(char*, byte*, byte*, byte, byte)
I'd guess.

Look carefully at the code box under the heading "Creation"
http://www.arduino.cc/playground/Code/Keypad

When you post code to the forum, please use the # icon in the editor's toolbar to put the code in a proper code box.
« Last Edit: March 06, 2011, 11:26:12 am by Groove » Logged

Per Arduino ad Astra

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


You missed a thing - http://www.arduino.cc/playground/Code/Keypad -

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Thank you guys!
Logged

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

One more question. Is it necessary to setDebounceTime for this situacion, which I am in?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on the switch type of your pad, but I'd probably say yes.
Logged

Per Arduino ad Astra

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

Thank you, Groove smiley
Logged

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

I wrote a code and I need some corrections, if they are necessary. So, If I am right, this code should do just like that: the true password is 1234, I write ' * ' then I can guess a password, if it's wrong, the LED won't turn on and it will reset, if I write 1234, the LED will turn on. Am I right? Please, correct me, if it's necessary smiley

Code:
#include <Password.h>
#include <Keypad.h>

Password password = Password( "1234" );

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 keypad
byte colPins[cols] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

const byte ledPin = 13;

void setup(){
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  digitalWrite(ledPin, HIGH);   // sets the LED on
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
 
void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset(); break;
default:
password.append(eKey);
  }
}

void guessPassword()
{
if (password.evaluate())
{
digitalWrite(ledPin,HIGH);
}else{
digitalWrite(ledPin,LOW);
}
}
Logged

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

Can any one help, please? smiley
Logged

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

Quote
Am I right?

You're the one with the hardware - what do you observe?
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.

Offline Offline
Full Member
***
Karma: 0
Posts: 200
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can any one help, please? smiley

 Just to clarify, do you have an arduino unit and a keypad, or are you unable to test your code because you are writing and debugging it without having the hardware?
Logged

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

I have the keypad, but my arduino board is on it's way, so I have some time for code. You right, brucethehoon, I am writing and debugging my code.  I am trying to find out, did I correctly understand all functions and etc. So, I am just asking some corrections or advises from professionals, if something is wrong with my code.

Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 200
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which keypad did you get? do you have a URL?  If it's identical or close to one that I own, I might be able to set things up and test here.  If it's close to or identical to the Sparkfun physical 3x4, I can test it out if you can tell me exactly which wiring configuration you have in mind.  I wrote up the datasheet for that one:
http://www.sparkfun.com/products/8653

Logged

Pages: [1]   Go Up
Jump to: