Go Down

Topic: Start with keypad and password (Read 1 time) previous topic - next topic

binfazen

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

robtillaart


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,
Rob Tillaart

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

binfazen

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?

Groove

#3
Mar 06, 2011, 05:23 pm Last Edit: Mar 06, 2011, 05:26 pm by Groove Reason: 1
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.
Per Arduino ad Astra

robtillaart


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

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

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


binfazen

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

Groove

It depends on the switch type of your pad, but I'd probably say yes.
Per Arduino ad Astra


binfazen

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 :)

Code: [Select]
#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);
}
}

binfazen


AWOL

Quote
Am I right?


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

brucethehoon


Can any one help, please? :)


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?

binfazen

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.


brucethehoon

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


Go Up