Using this as a guide~
I disabled all of my serial code and moved the 3rd column pin from pin 10 to pin 1. AND EVERYTHING WORKS! Except for the screen after the press * to arm or # to disarm page, but thats only because I took that code out just to make sure it wasn't interfering.
That's my code as of now.
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int pressCnt = 0;
#define Password_Length 5
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
enum MODES
{
MAINMENUMODE,
SECURITYMODE,
SECURITYMODETWO,
COOPMODE
};
MODES mode = MAINMENUMODE;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long ScreenRefresh = 5000;
boolean RefreshDone = false;
boolean DoorIsOpen = false;
boolean DoorIsClosed = false;
int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 1};
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinMode(10, OUTPUT);
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.setChannel(100);
radio.setRetries(15, 15);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1, pipes[1]);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();
startMillis = millis();
//Screen 1
lcd.begin(16, 2);
MainMenu();
}
void loop() {
currentMillis = millis();
char myKey = myKeypad.getKey();
if (radio.available()) {
radio.read(msg, 1);
if (msg[0] == 111) {
DoorIsOpen = true;
DoorIsClosed = false;
}
if (msg[0] == 112) {
DoorIsClosed = true;
DoorIsOpen = false;
}
}
if (myKey == '*' ) {
mode = COOPMODE;
currentMillis = millis();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The Coop Door Is");
CoopDoorIs();
}
if (mode == COOPMODE) {
if (currentMillis - startMillis >= ScreenRefresh) {
CoopDoorIs();
startMillis = currentMillis; //save the time that it was refreshed
RefreshDone = true;
}
}
if (RefreshDone == true) {
ClearScreen();
RefreshDone = false;
}
if (myKey == '#') {
mode = SECURITYMODE;
pressCnt = 0;
SecurityScreen();
}
if (mode == SECURITYMODE && myKey == '*') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Invalid Key ");
delay (2000);
SecurityScreen();
}
else if (mode == SECURITYMODETWO && myKey == '*') {
ArmedScreen();
}
else if (mode == SECURITYMODETWO && myKey == '#') {
DisarmScreen();
}
if (mode == SECURITYMODE) {
if (myKey >= '0' && myKey <= '9') {
Data[pressCnt] = myKey;
lcd.setCursor(pressCnt, 1);
lcd.print('*');
pressCnt++;
}
}
if (pressCnt == Password_Length - 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password Is ");
if (!strcmp(Data, Master)) {
lcd.print("Good");
delay(1000);
clearData();
SecurityScreenTWO();
}
else {
lcd.print("Bad");
delay(1000);
clearData();
MainMenu();
}
}
}
void clearData() {
while (data_count != 0)
{
Data[data_count--] = 0;
}
pressCnt = 0;
return;
}
void MainMenu () {
mode = MAINMENUMODE;
lcd.setCursor(0, 0);
lcd.print("* for Coop");
lcd.setCursor(0, 1);
lcd.print("# for Security");
}
void CoopDoorIs() {
if (DoorIsOpen == true && DoorIsClosed == false) {
lcd.setCursor(0, 1);
lcd.print("Open");
}
else if (DoorIsClosed == true && DoorIsOpen == false ) {
lcd.setCursor(0, 1);
lcd.print("Closed");
}
}
void SecurityScreen() {
mode = SECURITYMODE;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter Password");
}
void SecurityScreenTWO() {
mode = SECURITYMODETWO;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("* To Arm");
lcd.setCursor(0, 1);
lcd.print("# To Disarm");
}
void ArmedScreen() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Security System");
lcd.setCursor(0, 1);
lcd.print(" Is ARMED ");
}
void DisarmScreen () {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Security System Is");
lcd.setCursor(0, 1);
lcd.print(" Disarmed ");
}
void ClearScreen ()
{
delay(1500);
lcd.clear();
MainMenu();
}