Go Down

Topic: How can I insert the password.keypad example in my code ? (Read 1 time) previous topic - next topic

enterpc

I have this code
Code: [Select]


#include <Wire.h>
#include <PCFCrystal.h>
#include <i2ckeypad.h>
#include <Password.h>

Password password = Password( "1234" );

byte buffer = 0;

PCFCrystal lcd(B00100000, B00010000, B00000001, B00000010, B00000100, B00001000, 0x39, &buffer);
const int buttonPin = 2;
int buttonState = 0;

#define ROWS 4
#define COLS 4


#define PCF8574_ADDR 0x38


i2ckeypad kpd = i2ckeypad(PCF8574_ADDR, ROWS, COLS);

void setup() {
   Serial.begin(9600);
  Wire.begin();
    lcd.begin(16, 2);
  lcd.setCursor(0,0);

    pinMode(buttonPin, INPUT);
      kpd.init();


  Serial.print("Testing keypad/PCF8574 I2C port expander arduino lib\n\n");
}

void loop() {
  buttonState = digitalRead(buttonPin);

 


   
     char key = kpd.get_key();

  if(key) {
        switch (key)
    {
      case '5':
        lcd.setCursor(0,0);
    lcd.print("5                     ");
        break;
      case '9':
       lcd.setCursor(0,0);
    lcd.print("9                       ");
        break;
      default:
        Serial.println(key);
       
 
    }

  }
  void keypadEvent(KeypadEvent eKey){
}





And i need to I connect this code

Code: [Select]


/*
||
|| @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);
}
}





When I have insert  this ( void keypadEvent(KeypadEvent eKey){)
I have the error

sorry I'am new in Arduino

PaulS

Quote
I have the error

sorry I'am new in Arduino

That error is only correctable with experience.

Perhaps you meant a different error?

enterpc

need I use the keypad.h ? i use the I2Ckeypad.h
can I insert the password.h ?Is it possible?

PaulS

Quote
need I use the keypad.h ? i use the I2Ckeypad.h

Use the one that goes with the keypad you have. If you have an I2C keypad, use the I2Ckeypad library. Otherwise, don't.

Quote
can I insert the password.h ?Is it possible?

Yes and yes.

enterpc

I try to compile this two code but when I insert (  keypad.addEventListener(keypadEvent); )  I have this error
Code: [Select]




i2c_keypadand_lcd.cpp: In function 'void setup()':
i2c_keypadand_lcd:30: error: 'keypad' was not declared in this scope
i2c_keypadand_lcd:30: error: 'keypadEvent' was not declared in this scope



If,I understood correctly it is not included in I2ckeypad.h But it included in keypad.h
please can you help me?

enterpc

? tried to I edit  the I2Ckeypad.h but I didn't I managed it .
have someone any idea ? what must  I try?

Did you achieve this? I want to do exactly what you wanted... <i2ckeypad.h> & <Password.h>

Good I speak two languages, I found the solution in Spanish... The only problem with the Library is 1.0 compatibility. You need to change in Password.h #include <WProgram.h> for #include <Arduino.h> and the library works great!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy