Hi.
I'm quite new to this but I hope that someone can help me please?
I am making a basic keypad entry system.
The code is below:
/*
This sketch takes input from a keypad for a PIN code.
If the code is entered correctly, it turns on a GREEN LED to simulate access granted.
If an invalid code is entered, the RED LED is lit.
*/
#include <Keypad.h> // Include the Keypad library.
#define GREENLED 10 // Define the Green LED as Digital Pin 10.
#define REDLED 11 // Define the Red LED as Digital Pin 11.
char* ourCode = "1974"; // Set the required PIN code.
int currentPosition = 0; // Keeps track of the position of the code entered.
const byte rows = 4; // Define the amount of rows and columns for the keypad.
const byte cols = 4;
char keys[rows][cols] = { // Define the characters of the keypad.
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[rows] = {2,3,4,5}; // Define the pins connected to the keypad.
byte colPins[cols] = {6,7,8,9};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols); // Initialize the keypad.
void setup()
{
pinMode(REDLED, OUTPUT); // Set up the LED pins as outputs.
pinMode(GREENLED, OUTPUT);
digitalWrite(REDLED, LOW); // Turn the LEDs off.
digitalWrite(GREENLED, LOW);
}
void loop()
{
int l;
char key = keypad.getKey(); // Get the key press from the keypad.
if (int(key) != 0) { // Check to see if there is a value present.
for (l=0; l<=currentPosition; ++l)
{ }
if (key == ourCode[currentPosition]) // If the value is correct, increase he code position by one.
{
++currentPosition;
if (currentPosition == 4) // If all four parts of the code are correct, unlock the door.
{
unlockDoor();
currentPosition = 0;
}
}
else {
invalidCode(); // If any parts of the code are wrong, do not open the door.
currentPosition = 0;
}
}
}
void invalidCode()
{
digitalWrite(REDLED, HIGH); // Code to run when an incorrect code is entered.
delay(5000);
digitalWrite(REDLED, LOW);
}
void unlockDoor()
{
digitalWrite(GREENLED, HIGH); // Code to simulate unlocking the door.
delay(5000);
digitalWrite(GREENLED, LOW);
}
This all works fine for now.
What I would like to be able to do though, is have more than one PIN number.
I would like people to be able to have their own PIN number.
Is this possible?
Would my sketch be able to check more than one PIN number?
The reason for this, eventually this will be on a Leonardo and it will log the time and person to a PC.
Thanks in advance for any help.