next part of the project... im not sure where to post this so i just continued on with my thread maybe a mod can move it.
I am looking to use this code...
/** Imports **/
#include <Keypad.h>
/** Keypad **/
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] = {32,34,36,38};
byte colPins[COLS] = {33,35,37,39};
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
/** Pins **/
int ledPinRed = 50;
int ledPinGreen = 52;
int ledPinBlue = 52;
int lock = 22;
/** Variables **/
String passcode = "147A";
String debugMode = "ADBC";
String currentCode = "";
String tempCode = "";
String debug = "N";
String auth = "N";
int currentCodeCount = 0;
int tempInt = 0;
void setup()
{
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinBlue, OUTPUT);
pinMode(lock, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if(key != NO_KEY)
{
if(key == '*' && debug == "N")
{
flashGreenBlue(1000);
codeReset();
Serial.println("Cleared!");
}
else
{
currentCode = currentCode + key;
currentCodeCount += 1;
flashBlue(100);
Serial.println(currentCode);
}
if(debug == "N")
{
if(currentCode == passcode)
{
doorOpen();
codeReset();
}
else if(currentCode == debugMode)
{
analogWrite(ledPinRed, 127);
digitalWrite(ledPinGreen, HIGH);
codeReset();
debug = "Y";
}
else if(currentCodeCount == 4)
{
flashRed(4000);
Serial.println("Access Denied");
codeReset();
}
}
else
{
if(auth == "N")
{
if(currentCode == passcode)
{
digitalWrite(ledPinRed, LOW);
flashGreen(1000);
auth = "Y";
codeReset();
}
else if(currentCodeCount == 4)
{
digitalWrite(ledPinGreen, LOW);
flashRed(1000);
auth = "N";
debug = "N";
codeReset();
}
}
else
{
if(key == '*')
{
digitalWrite(ledPinBlue, HIGH);
while(tempInt < 4)
{
char key = kpd.getKey();
if(key != NO_KEY)
{
tempCode = tempCode + key;
tempInt += 1;
flashBlue(100);
}
}
digitalWrite(ledPinBlue, LOW);
flashGreen(100);
delay(100);
flashGreen(100);
setPasscode();
}
else if(key == '1')
{
digitalWrite(ledPinGreen, HIGH);
digitalWrite(lock, HIGH);
}
else if(key == '2')
{
digitalWrite(lock, LOW);
digitalWrite(ledPinGreen, LOW);
}
else if(key == '#')
{
codeReset();
flashRed(500);
auth = "N";
debug = "N";
}
}
}
}
}
/** Keypad Controls **/
void codeReset()
{
currentCode = "";
currentCodeCount = 0;
}
void setPasscode()
{
passcode = tempCode;
tempCode = "";
tempInt = 0;
}
/** Motor Controls **/
void doorOpen()
{
digitalWrite(ledPinGreen, HIGH);
digitalWrite(lock, HIGH);
Serial.println("Open");
delay(6500);
digitalWrite(ledPinGreen, LOW);
digitalWrite(lock, LOW);
Serial.println("Locked");
}
/** LED Control **/
void flashRed(int delayCount)
{
digitalWrite(ledPinRed, HIGH);
delay(delayCount);
digitalWrite(ledPinRed, LOW);
}
void flashGreen(int delayCount)
{
digitalWrite(ledPinGreen, HIGH);
delay(delayCount);
digitalWrite(ledPinGreen, LOW);
}
void flashBlue(int delayCount)
{
digitalWrite(ledPinBlue, HIGH);
delay(delayCount);
digitalWrite(ledPinBlue, LOW);
}
void flashGreenBlue(int delayCount)
{
digitalWrite(ledPinGreen, HIGH);
digitalWrite(ledPinBlue, HIGH);
delay(delayCount);
digitalWrite(ledPinGreen, LOW);
digitalWrite(ledPinBlue, LOW);
}
but i want to have (2) keypads.
how would i go about using multiple keypads. i have the mega so i have the pins to use 7 more i just dont know how the code would know which keypad was talking.