Hi! So i worked with the code some again and I realized that I needed to include CoopDoor(); in screen 2, in order to have something to refresh off of. Now I'm running into another issue.
After CoopDoor(); becomes open instead of closed, it won't switch back to closed until I rest the arduino (probably because of the boolean DoorState = LOW at the begining of the script). So for some reason DoorState isn't switching from high to low. I also have verified that the rf module is sending the correct information to the arduino.
Thanks!
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long ScreenRefresh = 5000;
boolean ScreenTwo = false;
boolean RefreshDone = false;
boolean doorState = LOW;
//Radio
int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};
//LCD
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
//Keypad
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
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();
Serial.begin(9600);
}
void loop() {
//Timing
currentMillis = millis();
//Keypad
char customKey = customKeypad.getKey();
if (customKey) {
Serial.println(customKey);
}
//Radio Code
if (radio.available()) {
bool done = false;
while (!done) {
done = radio.read(msg, 1);
if (msg[0] == 111) {
doorState = HIGH;
}
else if (msg[0] == 112) {
doorState = LOW;
}
}
}
// Screen 2
if (customKey == '*' ) {
currentMillis = millis();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The Coop Door Is");
ScreenTwo = true;
CoopDoor();
}
if (ScreenTwo == HIGH) {
if (currentMillis - startMillis >= ScreenRefresh) {
CoopDoor();
startMillis = currentMillis; //save the time that it was refreshed
RefreshDone = true;
}
}
if (RefreshDone == true) {
ClearScreen();
RefreshDone = false;
}
}
void CoopDoor() {
if (doorState == HIGH) {
lcd.setCursor(0, 1);
lcd.print("Open");
}
else if (doorState == LOW) {
lcd.setCursor(0, 1);
lcd.print("Closed");
}
}
void MainMenu () {
lcd.setCursor(0, 0);
lcd.print("* for Coop");
lcd.setCursor(0, 1);
lcd.print("# for Security");
}
void ClearScreen ()
{
ScreenTwo = false;
lcd.clear();
MainMenu();
}