Hi
I'm using a master and slave setup and I've come to a halt in my project since a value is not defined and I have no clue what to define it! Anyone here smart enough to help me? =) I've marked the error in the code with /////ERROR//////
#include <SPI.h>
#include <Keypad.h>
#include <MFRC522.h>
#include <Keypad.h>
#include<EEPROM.h>
#define SS_PIN 53
#define RST_PIN 5
#define change 0
#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int n = 1;
int x = 0;
int button1 = 3;
int button2 = 4; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int code = 0;
int codesize = 2;
int keypress = 0;
int unlock_code = (4);
int locked = 0;
char password[4];
char pass[4], pass1[4];
int i = 0;
char customKey = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'F'},
{'4', '5', '6', 'E'},
{'7', '8', '9', 'D'},
{'A', '0', 'B', 'C'}
};
byte rowPins[ROWS] = { 25, 24, 28, 22 };
byte colPins[COLS] = { 23, 27, 29, 26 };
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int m11;
int m12;
void setup() {
Serial.begin(9600); // start serial for output
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.print("Approximate your card to the reader...");
Serial.println();
pinMode(button2, INPUT_PULLUP);
pinMode(button1, INPUT_PULLUP);// declare pushbutton as input
// Switch on the backlight
delay(200);
pinMode(m11, OUTPUT);
pinMode(m12, OUTPUT);
Serial.print(" Welcome ");
Serial.print(" Keypad Lock ");
delay(2000);
Serial.println("Enter Ur Passkey:");
for (int j = 0; j < 4; j++)
EEPROM.write(j, j + 49);
for (int j = 0; j < 4; j++)
pass[j] = EEPROM.read(j);
}
void loop() {
{
if (digitalRead(button1) == LOW) //Button 1
{
code = (code + 1) ;
keypress = keypress + 1;
Serial.print("1");
delay(90);
}
//If the button is pressed write 2
if (digitalRead(button2) == LOW) //Button 2
{
code = (code + 2);
keypress = keypress + 1;
Serial.print("2");
delay(90);
}
// if the code entered matches the secret code then give access
if (keypress == codesize)
{
if (unlock_code == code)
{ locked = 1;
Serial.println("Acess Granted");
delay(200);
code = 0;
locked = 0;
keypress = 0;
}
else //if the code entered does not match with the secret code then write acess denied
{
Serial.println("Acess Denied");
code = 0;
locked = 0;
keypress = 0;
}
}
}
{
digitalWrite(11, HIGH);
customKey = customKeypad.getKey();
if(customKey=='#')
change(); ////////////////////////////////////////////ERROR HERE/////////////////////
if (customKey)
{
password[i++]=customKey;
lcd.print(customKey);
Serial.print(customKey);
}
if(i==4)
{
delay(200);
for(int j=0;j<4;j++)
pass[j]=EEPROM.read(j);
if(!(strncmp(password, pass,4)))
{
lcd.clear();
lcd.print("Passkey Accepted");
Serial.println("Passkey Accepted");
digitalWrite(11, LOW);
delay(2000);
lcd.setCursor(0,1);
lcd.print("#.Change Passkey");
Serial.println("#.Change Passkey");
delay(2000);
lcd.clear();
lcd.print("Enter Passkey:");
Serial.println("Enter Passkey:");
lcd.setCursor(0,1);
i=0;
}
else
{
digitalWrite(11, HIGH);
lcd.clear();
lcd.print("Access Denied...");
Serial.println("Access Denied...");
lcd.setCursor(0,1);
lcd.print("#.Change Passkey");
Serial.println("#.Change Passkey");
delay(2000);
lcd.clear();
lcd.print("Enter Passkey:");
Serial.println("Enter Passkey:");
lcd.setCursor(0,1);
i=0;
}
}
}
void change() ////////////////////////////////////////////ERROR HERE/////////////////////
{
int j=0;
lcd.clear();
lcd.print("UR Current Passk");
Serial.println("UR Current Passk");
lcd.setCursor(0,1);
while(j<4)
{
char key=customKeypad.getKey();
if(key)
{
pass1[j++]=key;
lcd.print(key);
Serial.print(key);
}
key=0;
}
delay(500);
if((strncmp(pass1, pass, 4)))
{
lcd.clear();
lcd.print("Wrong Passkey...");
Serial.println("Wrong Passkey...");
lcd.setCursor(0,1);
lcd.print("Better Luck Again");
Serial.println("Better Luck Again");
delay(1000);
}
else
{
j=0;
lcd.clear();
lcd.print("Enter New Passk:");
Serial.println("Enter New Passk:");
lcd.setCursor(0,1);
while(j<4)
{
char key=customKeypad.getKey();
if(key)
{
pass[j]=key;
lcd.print(key);
Serial.print(key);
EEPROM.write(j,key);
j++;
}
}
lcd.print(" Done......");
Serial.println(" Done......");
delay(1000);
}
lcd.clear();
lcd.print("Enter Ur Passk:");
Serial.println("Enter Ur Passk:");
lcd.setCursor(0,1);
customKey=0;
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "9E 6E 64 55") //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized Access");
delay(2000);
Serial.println();
Wire.write(3);
Wire.endTransmission();
}
[code/]