I added you code and took your advice, but I can't get CoopDoor(); to display, if I go to the second screen it's blank where closed and open should be. It's like it's not running CoopDoor(); in that millis function. I tried moving CoopDoor(); back into the screen 2 function, but that didn't solve anything. I also verified that radio connection was happening by using an other stable script.
#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 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;
}
if (ScreenTwo == HIGH) //if we are showing screen 2
{
if (currentMillis - startMillis >= ScreenRefresh) //if the period has passed
{
CoopDoor(); //refresh the screen
startMillis = currentMillis; //save the time that it was refreshed
ClearScreen();
}
}
}
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 = LOW;
lcd.clear();
MainMenu();
}