#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
int keys[ROWS][COLS] = {
{ 1, 2, 3, 0 },
{ 4, 5, 6, 0 },
{ 7, 8, 9, 0 },
{ 0, 0, 0, 0 }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
#define pir1 10
#define pir2 11
#define pir3 12
#define pir4 13
#define pir5 14
#define pir6 15
#define light1 16
#define light2 17
#define light3 18
#define light4 19
#define light5 22
byte lightBanks [] = {1,1,1,1,0};
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
byte lastState = 3;
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.println("Setup Complete");
delay(1500);
lcd.clear();
pinMode(pir1, INPUT);
pinMode(pir2, INPUT);
pinMode(pir3, INPUT);
pinMode(pir4, INPUT);
pinMode(pir5, INPUT);
pinMode(pir6, INPUT);
pinMode(light1, OUTPUT);
pinMode(light2, OUTPUT);
pinMode(light3, OUTPUT);
pinMode(light4, OUTPUT);
pinMode(light5, OUTPUT);
}
void loop() {
int key = keypad.getKey();
if (key != NO_KEY) {
lcd.clear();
lcd.println(key);
lightBanks[key-1] = lightBankSet(key,lightBanks);
lcd.clear();
lcd.println(lightBanks[key-1]);
}
byte sensor = digitalRead(pir1);
if(lastState != sensor){
lcd.clear();
lcd.println(sensor);
lastState = sensor;
digitalWrite(light1,sensor);
}
}
byte sensorRead(){
}
byte lightBankSet(int key,byte lightBanks[]){
byte stateChange;
switch (lightBanks[key-1]){
case 0:
lcd.clear();
lcd.print("light Bank ");
lcd.print(key);
lcd.print(" ON");
delay (1000);
stateChange = 1;
break;
case 1:
lcd.clear();
lcd.print("light Bank ");
lcd.print(key);
lcd.print(" OFF");
delay (1000);
stateChange = 0;
}
return stateChange;
}