// Program written by Dan Hostler, August 2020.
// Feel free to use   as you need to.
// PayPal donations appreciated at [email protected]




//   LIBRARIES. (PLEASE INSTALL THESE LIBRARIES IF YOU HAVE NOT YET)
#include <Wire.h>                // deals with I2C connections
#include <LiquidCrystal_I2C.h>  //   activates the LCD I2C library
#include <Keypad.h>             // activates the   Keypad library




// VARIABLES FOR THE 8-NUMBER PASSWORD INPUT DATA
#define   Password_Length 4                 // Amount of digits plus one null character   (8 + 1 = 9) defines password length
char userInput[Password_Length];             //   This variable will store the user input in a string
char Master[Password_Length]   = "1234";   // This variable holds the correct password that the user string   must match, change as needed
char customKey;                              //   This variable holds key input of every key pressed
int pressCount;                      //   This variable holds a counter for the amount of times the keys were pressed




//   KEYPAD CONFIGURATION (PLEASE MODIFY THIS SECTION IF YOUR KEYPAD WIRING IS DIFFERENT   FROM BELOW)
const byte ROWS = 4; // Constants for row and 
const byte COLS   = 3; // column size of your keypad.

char twelveKeys[ROWS][COLS] =                     //   Physical layout of the keypad being used in this program
{ 
    {'1', '2', '3'}, 
    {'4', '5', '6'},
    {'7', '8', '9'},
    {'C', '0', 'E'} //   C = CLEAR, E = ENTER
};

byte rowPins[ROWS] = {9, 8, 7, 6};  // Defines   how rowPins are connected on the Arduino to the keypad: 9 = R1, 8 = R2, 7 = R3,   6 = R4
byte colPins[COLS] = {5, 4, 3};     // Defines how colPins are connected   on the Arduino to the keypad: 5 = C1, 4 = C2, 3 = C3, 2 = C2 (if you have a 4x4   keypad) 




// OBJECT CONFIGURATIONS
Keypad customKeypad = Keypad(makeKeymap(twelveKeys),   rowPins, colPins, ROWS, COLS); // Creates keypad "object"
LiquidCrystal_I2C   lcd(0x27, 16, 2);                                                 // Creates LCD   "object" (I2C address, rows, columns)




// PROGRAM SETUP
void   setup() {

  // LCD Initialization
  lcd.backlight(); 
  lcd.init();
   lcd.clear();

  Serial.begin(9600); // Must be 9600
  Serial.println("Hello Arduino\n");
}




// MAIN PROGRAM LOOP
void loop() {

  Serial.println(pressCount);
  customKey = customKeypad.waitForKey();

  if (customKey != NO_KEY)    // If the   user presses the number keys, the data is entered
  {                                                    // Asterisks are printed for   confidentiality 
    pressCount++;                                                       //   Key press count will roll over until 8 digits are entered
  }

  if (pressCount >= 4)
  {
    //pressCount >= 4
    Serial.println("more");
    pressCount = pressCount - 4;
  }

}

/*int main() {
  int x = 5;
  int y = 3;
  cosh << (x >= y); // returns 1 (true) because five is greater than, or equal, to 3
  return 0;
}*/