#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define REST 0
#define RED 13
#define GREEN 12
#define PURPLE 11
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
//speed
int tempo = 85;
int counter_found=0;
int buzzer = 2;
int divider = 0, noteDuration = 0;
#define MOBILE_NUMBER_LENGTH 10
#define MAX_ENTRIES_PER_MOBILE_NUMBER 2
#define MAX_ENTRIES 100
char mobileNumbers[10][11] =
{
"6396979579",
"9536977024",
"9389724663",
"9997023797",
"8219688819",
"8171483009",
"7890123456",
"8901234567",
"7302166870",
"0123456789"
};
unsigned long entryTimes[MAX_ENTRIES][2];
int entryCount = 0;
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] = {10, 9, 8, 7};
byte colPins[COLS] = {6, 5, 4, 3};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int attemp=0;
int key;
int found=0;
int mil_gya=0;
void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(PURPLE, OUTPUT);
Serial.begin(9600);
display_at_start();
// LCD.setCursor(0, 1);
// LCD.println("JEEVAN PRAKASH");
}
void display_at_start()
{
LCD.init();
LCD.backlight();
LCD.setCursor(4, 0);
LCD.print("WELCOME...");
delay(2000);
LCD.clear();
LCD.setCursor(3, 0);
LCD.print("LOADING...");
delay(1000);
}
void loop()
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("ENTER ID: ");
digitalWrite(13, HIGH);
digitalWrite(11, HIGH);
int i=0;
char inputNumber[11] = "";
LCD.setCursor(0, 1);
while(i<10)
{
char key = keypad.getKey();
if (key != NO_KEY && key != '*' && key != '#')
{
Serial.print(key);
LCD.print(key);
inputNumber[i] = key;
i++;
}
if(key=='*')
{
Serial.println("\nCode break !");
tone(2, 510,180);
delay(300);
tone(2, 130,180);
delay(300);
tone(2, 510,180);
break;
}
if(key=='#')
{
Serial.println("\nCode break !");
tone(2, 510,180);
delay(300);
tone(2, 130,180);
delay(300);
tone(2, 510,180);
break;
}
}
for (int i = 0; i < 10; i++)
{
if (strcmp(mobileNumbers[i], inputNumber) == 0)
{
Serial.println("\nId found!");
LCD.clear();
LCD.print("ID found!");
tone(2,500,300);
found = 1;
int count = 0;
unsigned long now = millis();
for (int s = 0; s < entryCount; s++)
{
if ((strcmp(mobileNumbers[i], (char*)entryTimes[s][0]) == 0))
{
if (now - entryTimes[s][1]<=86400000)
{
// Serial.println(counter_found);
counter_found++;
count++;
}
}
}
if (count >= MAX_ENTRIES_PER_MOBILE_NUMBER)
{
Serial.println("REPEATED ID !");
LCD.clear();
LCD.print("LIMIT EXCEED");
tone(2,200,200);
delay(500);
tone(2,200,200);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
counter_found=0;
delay(2000);
break;
}
else
{
if(counter_found<2)
{
entryTimes[entryCount][0] = (unsigned long)mobileNumbers[i];
entryTimes[entryCount][1] = now;
entryCount = (entryCount + 1) % MAX_ENTRIES;
Serial.println("ID ACCEPTED");
LCD.clear();
LCD.print("PRESS TO BUY");
mil_gya=1;
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
digitalWrite(11, LOW);
delay(10000); // 10 sec delay to choose...
digitalWrite(12, LOW);
LCD.clear();
break;
}
}
}
if (i == 9)
{
Serial.println("\nID NOT FOUND");
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("ID NOT FOUND !");
//security....
if(attemp==5)
{
police();
}
attemp++;
tone(2,200,200);
delay(500);
tone(2,200,200);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
delay(2000);
loop();
}
}
delay(500);
}
void police()
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("MACHINE LOCKED !");
int j=0;
while(j!=10)
{
Serial.println("\nALARM ACTIVATED [10 SECOND] !");
tone(2,200,1000);
delay(500);
tone(2,500,500);
delay(500);
j++;
}
attemp=0;
Serial.println("\nMACHINE LOCKED [20 SECOND] !");
delay(20000);
loop();
}