Greetings all.
First off i am new to all things arduino and script making. i have soon got the hang of changing things in the script i am using though for this project to make it more suitable for me.
here is the script i am using:
#include <Password.h>
#include <Keypad.h>
Password password = Password( "123" ); //password to unlock, can be changed
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'A', '0', 'B'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 5, 4, 2, 3 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
Serial.write(254);
Serial.write(0x01);
delay(200);
pinMode(9, OUTPUT); //green light
pinMode(10, OUTPUT); //red light
pinMode(11, OUTPUT); //relay
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 (keypad.getState()) {
case PRESSED:
Serial.print("Enter:");
Serial.println(eKey);
delay(10);
Serial.write(254);
switch (eKey) {
case 'A': checkPassword(); delay(1); break;
case 'B': password.reset(); delay(1); break;
default: password.append(eKey); delay(1);
}
}
}
void checkPassword() {
if (password.evaluate()) { //if password is right open
Serial.println("Accepted");
Serial.write(254); delay(10);
//Add code to run if it works
digitalWrite(9, HIGH);//turn on
delay(1000); //wait 1 seconds
digitalWrite(11, HIGH);//turn on
delay(500); //wait 1 seconds
digitalWrite(11, LOW);// turn off
digitalWrite(9, LOW);// turn off
password.reset();
} else {
Serial.println("Denied"); //if passwords wrong keep locked
Serial.write(254); delay(10);
//add code to run if it did not work
digitalWrite(10, HIGH); //turn on
delay(500); //wait 5 seconds
digitalWrite(10, LOW);//turn off
password.reset();
}
}
is it possible to make it so one of the pins will pull high for a given length of time as soon as any button is pressed, to power a back light for the keypad?
also is it possible to make it so that every time a wrong code is entered it will make a pin(s) pull high (to power multiple small audio circuits) for a given length of time?
if so, how would i go about making those scripts.. could some one give me an example?
what i am trying to do is make a keypad lock with a pre-recorded computer generated voice.
access permitted, access denied, access denied. one attempt left, access denied lock down engaged
i will be using sound effects from the game Unreal and from the turrets on Unreal Tournament 99's "Chaos UT" expansion pack.
it will all become part of the door unlocking system on my project car for added effects
i will also in the future be creating a system where it will auto detect if it is dark and turn on lighting automatically when unlocked, then maybe adding a fully computerised engine start procedure with computer voice, but that would be another project and maybe a different arduino chip. (bigger one as i am only using a uno at the moment)!
Thanks all!