#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// LCD Connection:
// GND - GND
// VCC - 5V
// SDA - A4
// SCL - A5
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
// Keypad Arduino
// 1 2
// 2 3
// 3 4
// 4 5
// 5 6
// 6 7
// 7 8
// 8 9
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
String input_value;
long input_int;
#define D0 22
#define D1 23
#define D2 24
#define D3 25
int mode = 0;
int totalCycle = 10;
unsigned long previousTimeMode = 0;
int totalDoor = 0;
unsigned long delayAfterCycle = 10 * 1000;
unsigned long elapsed = 0;
unsigned long currentTime = 0;
unsigned long startTime = 0;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.clear();
lcd.backlight();
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
unsigned long startTime = millis();
}
void loop() {
// put your main code here, to run repeatedly:
if(mode == 0){
lcd.setCursor(18,0);lcd.print("M");lcd.print(mode);
lcd.setCursor(0,0);lcd.print("Cycle: ");lcd.print(totalCycle);
lcd.setCursor(0,1);lcd.print("Doors: ");lcd.print(totalDoor);lcd.setCursor(15,1);lcd.print("Run:A");
lcd.setCursor(0,2);lcd.print("Cycle Time: ");lcd.print(delayAfterCycle/1000);lcd.print("s");
lcd.setCursor(0,3);lcd.print("Next Page:C");
lcd.setCursor(14,3);lcd.print("Mode:D");
char key = keypad.getKey();
if(key){
}if(key == 'C'){
lcd.clear();
mode = 1;
unsigned long startTime = millis();
unsigned long elapsed = 0;
}else if(key == 'D'){
}else if(key == 'A'){
lcd.clear();
mode = 2;
unsigned long startTime = millis();
unsigned long elapsed = 0;
lcd.clear();
}
}else if(mode == 1){
lcd.setCursor(18,0);lcd.print("M");lcd.print(mode);
lcd.setCursor(0,3);lcd.print("Back Page:C");
char key = keypad.getKey();
if(key){
}if(key == 'C'){
lcd.clear();
unsigned long currentTime = millis();
unsigned long elapsed = 0;
mode = 0;
}else if(key == 'D'){
}else if(key == 'A'){
}
}else if(mode == 2){
elapsed = (millis() - startTime);
lcd.setCursor(0,0);lcd.print(elapsed);
}
}