Hi all, I have an Arduino Uno and i'm making a basic project whereby the user uses a keypad to enter the current year, if the current year is correct it will fire a relay. For some reason this code will upload fine but the arduino wont do anything once uploaded. If I leave out the array and just use a static password (Password password = Password ("1234") it works fine.
This is the code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
DateTime now = RTC.now();
char passyear[5] = {now.year()};
Password password = Password (passyear) ;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define relay 3
#define speakerPin 13
void setup(){
Wire.begin();
RTC.begin();
pinMode (3, OUTPUT);
pinMode (13, OUTPUT);
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){
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*': guessPassword(); break;
case '#': password.reset(); break;
default:
password.append(eKey);
}
}
void guessPassword(){
Serial.print("Guessing password... ");
if (password.evaluate()){
digitalWrite(speakerPin,HIGH);
digitalWrite(relay,HIGH);
delay (2000);
digitalWrite(relay,LOW);
Serial.print("Correct");
}else{
Serial.print("false");
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.