#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
byte num[8]={1,2,4,8,16,32,64,128};
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String printting(String word){
int i;
delay(500);
lcd.clear();
lcd.setCursor(3, 0);
lcd.print(word);
for (i=0;i<3;i++){
lcd.print(".");
delay(500);
}
lcd.clear();
lcd.setCursor(3, 0);
lcd.print(word);
for (i=0;i<3;i++){
lcd.print(".");
delay(500);
}
}
void initLED()
{
DDRA=0x00;
DDRC=0x00;
DDRF=0x00;
DDRK=0x00;
}
void outA(byte num)
{
PORTA=num^0x00 ;
}
void outC(byte num)
{
PORTC=num^0x00 ;
}
void outF(byte num)
{
PORTF=num^0x00 ;
}
void outK(byte num)
{
PORTK=num^0x00 ;
}
void setup(){
initLED();
outA(0);
outC(0);
outF(0);
outK(0);
Serial.begin(9600);
lcd.init();
lcd.begin(16,2);
lcd.backlight();
unsigned char Azone = 0;
unsigned char Bzone = 0;
unsigned char Czone = 0;
}
void loop(){
delay(500);
lcd.clear();
while(1){char key=keypad.getKey();lcd.setCursor(4,0);lcd.print("Standby");if (key!=NO_KEY){break;}}
delay(500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Zone|");
char Zone;
char Slot1,Slot2;
String Action;
char key;
while (1){ //Zone
char key=keypad.getKey();
if (key=='A'){lcd.print(key);Serial.println(key);Zone = key;break;}
if (key=='B'){lcd.print(key);Serial.println(key);Zone = key;break;}
if (key=='C'){lcd.print(key);Serial.println(key);Zone = key;break;}
}
lcd.print(" Slot|");
while (1){
char key=keypad.getKey();
if (key!=NO_KEY){lcd.print(key);Serial.println(key);
Slot1 = key;
break;
}
}
while (1){
char key=keypad.getKey();
if (key!=NO_KEY){lcd.print(key);Serial.println(key);
Slot2 = key;
break;
}
}
lcd.setCursor(2,1);
lcd.print("=");
lcd.setCursor(5,1);
while (1){ //Open or Close
char key=keypad.getKey();
if (key=='*'){Action = "Close";Serial.println(key);break;}
if (key=='#'){Action = "Open";Serial.println(key);break;}
}
lcd.print(Action);
int nslot1=Slot1-'0';
int nslot2=Slot2-'0';
int new_slot = 10*nslot1+nslot2;
if (Action == "Open"){
if (Zone == 'A'){
outA(num[(new_slot-1)]);
}
if (Zone == 'B'){
if (new_slot<=3){
outA(num[(new_slot+4)]);
}
else if (new_slot<=5){
outC(num[(new_slot-4)]);
}
}
if (Zone == 'C'){
outC(num[(new_slot+1)]);
}
}
if (Action == "Close"){
if (Zone == 'A'){
outF(num[(new_slot-1)]);
}
if (Zone == 'B'){
if (new_slot<=3){
outF(num[(new_slot+4)]);
}
else if (new_slot<=5){
outK(num[(new_slot-4)]);
}
}
if (Zone == 'C'){
outK(num[(new_slot+1)]);
}
}
delay(1000);
}