appreciate your codes but i need something that would work with my project as im not using keypad.h. I also have the following codes that works like a charm but with 8 pins of Arduino.
/*
Author: Danny van den Brande. Arduinosensors.nl. BlueCore Tech.
Hello world! This code is made to put a
access code/password protection on your dangerous machines in the garage/work place for example.
To protect your kids from the danger that might lurk in your garage, without the code.
power cannot be turned on. Hide it in a box with that you can lock on the wall
and add a little safery to your garage. Of course it can be used to turn on/off anything.
*/
#include <Keypad.h>
#include <Password.h>
int relay1 = 2;
int relay2 = 3;
int noAccesled = 9;
int AccesLed = 10;
int noAcces = 1;
int passinput = 0;
long flashvarled = 0;
long flashtimeled = 300;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {
A1};
byte colPins[COLS] = {
A1};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Password password = Password("6240"); // change the access code here
void setup(){
Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, 255);
pinMode(relay2, OUTPUT);
digitalWrite(relay2, 255);
pinMode(noAccesled, OUTPUT);
digitalWrite(noAccesled, 255);
pinMode(AccesLed, OUTPUT);
digitalWrite(AccesLed, 0);
}
void loop(){
char key = keypad.getKey();
if(noAcces){
if(passinput){
unsigned long currentvarled = millis();
if(currentvarled - flashvarled > flashtimeled) {
flashvarled = currentvarled;
digitalWrite(noAccesled, !digitalRead(noAccesled));
}
}
else{
digitalWrite(noAccesled, 255);
}
digitalWrite(AccesLed, 0);
}
if (key != NO_KEY){
Serial.println(key);
password.append(key);
passinput = 1;
delay(100);
if(key == '*'){
password.reset();
passinput = 0;
noAcces = 1;
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
}
if(password.evaluate()) {
noAcces = !noAcces;
password.reset();
passinput = 0;
}
if(!noAcces) {
passinput = 0;
digitalWrite(noAccesled, 0);
digitalWrite(AccesLed, 255);
switch (key) {
case 'A':
digitalWrite(relay1, !digitalRead(relay1));
break;
case 'B':
digitalWrite(relay2, !digitalRead(relay2));
break;
break;
}
password.reset();
}
}
}