Translate

Friday 16 May 2014

Room Management System – The Menu – part 7


First thing today, we add the last sub menu controlling the room lights. As mentioned in the last post, corridors are usually centralised little rooms connecting everything else with no windows what so ever. There fore it's no real use, using up space in programming timers for it, which are not used anyway. However, I did activate the option to adjust the delay timer for normal operation.
Let's go to the end of the selectMenu() function to the last mark “} //submenu end” and add the following bit of code just below:

if(menuOption == 16){ //and menu option is 16 (room 10)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.print("10"); //printing assigned room number 10

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[9] = get_delay(9, 10, dLiving);

return;

}

if(submenu == 2) return;

if(submenu == 3) return;

if(submenu == 4) return;

if(submenu == 5) return;

if(submenu == 6) return;

if(submenu == 7) return;

}

}

} //submenu end

Since we do not address any timers at this point, where variables have to be passed back in the get_setTime() function, we can skip this process for room 10. We will take care of this a little later, when we do the preparations for storing and reading variables from EEPROM.

Let's start again with some housekeeping. When I did the timers for the automated light operation while nobody is at home, I had a project in mind I am currently working on. However, at this state I would like to make the unit as universal to use as any possible. In conjunction with the preparation of using the EEPROM memory for the variable storage, the variables for the room timers go into a 3 dimensional array room_timers[room][timer][time]. Room is holding the assigned room number minus 1 since we start counting the rooms with 1 and in an array the count always starts with 0. The same goes for the timer. Since we are just implementing this partition, we start the timer count with 0, same as the array count and the 4 parts of the time settings, hour on, minute on, hour off and minute off. To make it a bit more flexible, I extended the timers to 4 for the main room like bed rooms and the living area. The bathrooms and the corridor is having two timers and for the kitchen we make it 2.

The first thing we do is building our array and add it to the declaration part of the sketch.

//////////////////////holiday timer settings//////////////////////

////////////Room 1 (Bed 1) ///////////

byte room1MActive = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room1O1Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room102Active = 1; //Set to 1 if you want to process

byte room103Active = 0;

////////////Room 2 (Bed 2) ///////////

byte room2MActive = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room201Active = 1; //Set to 1 if you want to process

byte room202Active = 0;

byte room203Active = 0

////////////Room 3 (Bed 3) ///////////

byte room3MActive = 1; //Set to 1 if you want to process

byte room301Active = 1; //Set to 1 if you want to process

byte room302Active = 1; //Set to 1 if you want to process

byte room303Active = 1; //Set to 1 if you want to process

///////////Room 4 {Living)

byte room4MActive = 0;

byte room401Active = 1; //Set to 1 if you want to process

byte room402Active = 0;

byte room403Active = 0;

//////////Room 5 (bath 1)//////////

byte room5MActive = 1; //Set to 1 if you want to process

byte room501Active = 1; //Set to 1 if you want to process

//////////Room 6 (bath 2)//////////

byte room6MActive = 1; //Set to 1 if you want to process

byte room601Active = 1; //Set to 1 if you want to process

//////////Room 7 (bath 3)//////////

byte room7MActive = 1; //Set to 1 if you want to process

byte room701Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

//////////Room 8 (bath 4)//////////

byte room8MActive = 1; //Set to 1 if you want to process

byte room801Active = 0;

//////////Room 9 (Kitchen)//////////

byte room9MActive = 1; //Set to 1 if you want to process

byte room901Active = 1; //Set to 1 if you want to process

//////////Room 10 (corridor)///////

byte room10MActive = 0;

byte room1001Active = 0;

//Timer Settings room, timer, hour on, minute on, hour off, minute off

byte room_timers[10][4][4] = {

{

{5, 35, 6, 5}, //room 1 timer 1

{19, 35, 20, 15}, //room 1 timer 2

{21, 5, 21, 15}, //room 1 timer 3

{0, 0, 0, 0} //room 1 timer 4

},

{

{6, 30, 6, 50}, //room 2 timer 1

{19, 30, 20, 10}, //room 2 timer 2

{0, 0, 0, 0}, //room 2 timer 3

{0, 0, 0, 0} //room 2 timer 4

},

{

{5, 50, 6, 20}, //room 3 timer 1

{18, 10, 18, 25}, //room 3 timer 2

{19, 15, 19, 40}, //room 3 timer 3

{23, 20, 23, 35} //room 3 timer 4

},

{

{0, 0, 0, 0}, //room 4 timer 1

{17, 30, 23, 30}, //room 4 timer 2

{0, 0, 0, 0}, //room 4 timer 3

{0, 0, 0, 0} //room 4 timer 4

},

{

{5, 40, 5, 45}, //room 5 timer 1

{19, 55, 20, 10}, //room 5 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{6, 35, 6, 45}, //room 6 timer 1

{19, 50, 20, 5}, //room 6 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{6, 5, 6, 25}, //room 7 timer 1

{22, 50, 23, 15}, //room 7 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{0, 0, 0, 0}, //room 8 timer 1

{22, 5, 22, 20}, //room 8 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

},

{

{5, 50, 6, 45}, //room 9 timer 1

{17, 45, 18, 30}, //room 9 timer 2

{0, 0, 0, 0}, //room 9 timer 3

{0, 0, 0, 0} //not used

},

{

{0, 0, 0, 0}, //room 10 timer 1

{0, 0, 0, 0}, //room 10 timer 2

{0, 0, 0, 0}, //not used

{0, 0, 0, 0} //not used

}

};

///////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////DO NOT MODIVY BELOW HERE///////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

I think looking at the comments, it is pretty clear what belongs to what. But you may have noticed the changes in the part above the array. Since we put all the times in the new array, we don't need the single declarations any more and we can delete them.

////////////Room 1 (Bed 1) ///////////

byte room1MActive = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room1OnM[2] = {5, 35}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

byte room1OffM[2] = {6, 5}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

byte room1O1Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room1On1[2] = {19, 35}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

byte room1Off1[2] = {20, 15}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

byte room102Active = 1; //Set to 1 if you want to process

//Timer will be ignored when set to 0

byte room1On2[2] = {21, 5}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

byte room1Off2[2] = {21, 15}; //>>>>>>>>>>>>>DELETE<<<<<<<<<<<<

The same goes for the other rooms. We delete this statements until the code looks like the one above the room_timers[] array.

Since we add the corridor to the room timers, we need to add another variable. We move down to “////RTC and Holiday switch timers///”

/////////////////////////////RTC and Holiday switch timers///////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////

tmElements_t tm; //initializing RTC

byte room1Lights = 0; //var to hold the on command for room light

byte room2Lights = 0; //var to hold the on command for room light

byte room3Lights = 0; //var to hold the on command for room light

byte room4Lights = 0; //var to hold the on command for room light

byte room5Lights = 0; //var to hold the on command for room light

byte room6Lights = 0; //var to hold the on command for room light

byte room7Lights = 0; //var to hold the on command for room light

byte room8Lights = 0; //var to hold the on command for room light

byte room9Lights = 0; //var to hold the on command for room light

//>>>>>>>>>>>>>Add the line below<<<<<<<<<<<<<

byte room10Lights = 0; //var to hold the on command for room light

byte currentHour = 0; //var holding the time (hour 0-23)

byte currentMinute = 0; //var holding the time (minute 0-59)

byte currentDay = 0; //var holding the date (day 1-31)

byte currentDoM = 0; //var holding the weekday (Sun - Sat, 1-7)

byte currentMonth = 0; //var holding the date (month 1-12)

int currentYear = 0; //var holding the year (based on Unix time)

Next, we are adding the missing timers to the submenu. There fore we jump down to the “menu and user interface” section in the declaration part.

//storing the sub menu points in the program memory

prog_char submenu_0[] PROGMEM = "PIR delay R";

prog_char submenu_1[] PROGMEM = "HT1 Active R";

prog_char submenu_2[] PROGMEM = "Timer 1 R";

prog_char submenu_3[] PROGMEM = "HT2 Active R";

prog_char submenu_4[] PROGMEM = "Timer 2 R";

prog_char submenu_5[] PROGMEM = "HT3 Active R";

prog_char submenu_6[] PROGMEM = "Timer 3 R";

//>>>>>>>>>>>>>Addition starts here<<<<<<<<<<<<<<

prog_char submenu_7[] PROGMEM = "HT4 Active R";

prog_char submenu_8[] PROGMEM = "Timer 4 R";

//>>>>>>>>>>>>>Addition Ends here<<<<<<<<<<<<<<

PROGMEM const char *submenu_table[] = {

submenu_0,

submenu_1,

submenu_2,

submenu_3,

submenu_4,

submenu_5,

submenu_6,

//>>>>>>>>>>>>>Addition start here<<<<<<<<<<<<<

submenu_7,

submenu_8

//>>>>>>>>>>>>>Addition ends here<<<<<<<<<<<<<

};

void setup() {

//////////////Start Serial for Debugging/////////////////////

//Serial.begin(9600);

Now, we go down into the main loop again, where we are processing the Holiday lighting. We go down further just a bit to Room 1 (bed 1). If we look at the following to statements, we notice, that we are passing the variables, we just deleted in our declaration part. Here and at all the following statements where we check the room timers, we need to change the variables, so they match the 3-dimensional array we newly implemented.

//////////////Holiday lighting/////////////////////////

if(switchState[20] == 1) { //check if the holiday switch

//is activated

lightOutput[14] = 0; //make sure the master relay is off

//Serial.print("Current date: ");

//Serial.print(days[currentDay - 1]);

//Serial.print(", ");

//Serial.print(currentDoM);

//Serial.print("/");

//Serial.print(currentMonth);

//Serial.print("/");

//Serial.println(currentYear);

//Serial.print("Current Time: ");

//Serial.print(currentHour);

//Serial.print(" : ");

//Serial.println(currentMinute);

//Serial.print("Photo cell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 1 after: ");

//Serial.println(lightLevel[0]);

//Serial.print("photocell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 3 after: ");

//Serial.println(lightLevel[2]);

//Serial.print("Light level room 4 after: ");

//Serial.println(lightLevel[3]);

///////Room 1 (Bed 1) /////////////

if(room1MActive == 1 && currentHour >= room1OnM[0] &&

//changes to

if(room1MActive == 1 && currentHour >= room_timers[0][0][0] &&

//and

currentHour <= (room1OffM[0] + 1)){ //checking if we came passed

//changes to

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//and

//checking the times

room1Lights = checkOnTime(room1OnM[0], room1OnM[1],

//changes to

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

//and

room1OffM[0], room1OffM[1]);

//changes to

room_timers[0][0][2], room_timers[0][0][3]);

}

The complete revised statement for room1, timer 0 reads now:

if(room1MActive == 1 && currentHour >= room_timers[0][0][0] &&

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3]);

}

Here we go, we have to do this for every timer in every room. I guess, you can deal with the updates all the way through. Anyway, here is the part we just updated.

//////////////Holiday lighting/////////////////////////

if(switchState[20] == 1) { //check if the holiday switch

//is activated

lightOutput[14] = 0; //make sure the master relay is off

//Serial.print("Current date: ");

//Serial.print(days[currentDay - 1]);

//Serial.print(", ");

//Serial.print(currentDoM);

//Serial.print("/");

//Serial.print(currentMonth);

//Serial.print("/");

//Serial.println(currentYear);

//Serial.print("Current Time: ");

//Serial.print(currentHour);

//Serial.print(" : ");

//Serial.println(currentMinute);

//Serial.print("Photo cell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 1 after: ");

//Serial.println(lightLevel[0]);

//Serial.print("photocell switch: ");

//Serial.println(photocellSwitch);

//Serial.print("Light level room 3 after: ");

//Serial.println(lightLevel[2]);

//Serial.print("Light level room 4 after: ");

//Serial.println(lightLevel[3]);

///////Room 1 (Bed 1) /////////////

if(room1MActive == 1 && currentHour >= room_timers[0][0][0] &&

currentHour <= (room_timers[0][0][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3]);

}

if(room1O1Active == 1 && currentHour >= room_timers[0][1][0] &&

currentHour <= (room_timers[0][1][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][1][0], room_timers[0][1][1],

room_timers[0][1][2], room_timers[0][1][3]);

}

if(room102Active == 1 && currentHour >= room_timers[0][2][0] &&

currentHour <= (room_timers[0][2][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][2][0], room_timers[0][2][1],

room_timers[0][2][2], room_timers[0][2][3]);

}

if(room103Active == 1 && currentHour >= room_timers[0][3][0] &&

currentHour <= (room_timers[0][3][2] + 1)){ //checking if we came passed

//the hour where the lights

//to be switched on

//checking the times

room1Lights = checkOnTime(room_timers[0][3][0], room_timers[0][3][1],

room_timers[0][3][2], room_timers[0][3][3]);

}

if(room1Lights == 1 && lightLevel[0] == 1){ //if with in the on time

lightOutput[0] =1; //switch on the lights

}

else {

lightOutput[0] = 0; //other keep them off

lightLevel[0] = 0;

}

////////Room 2 (Bed 2)//////////////

if(room2MActive ==1 && currentHour >= room_timers[1][0][0]

&& currentHour <= (room_timers[1][0][2] + 1)){

room2Lights = checkOnTime(room_timers[1][0][0], room_timers[1][0][1],

room_timers[1][0][2], room_timers[1][0][3]);

}

if(room201Active == 1 && currentHour >= room_timers[1][1][0] &&

currentHour <= (room_timers[1][1][2] + 1)){

room2Lights = checkOnTime(room_timers[1][1][0], room_timers[1][1][1],

room_timers[1][1][2], room_timers[1][1][3]);

}

if(room202Active == 1 && currentHour >= room_timers[1][2][0] &&

currentHour <= (room_timers[1][2][2] + 1)){

room2Lights = checkOnTime(room_timers[1][2][0], room_timers[1][2][1],

room_timers[1][2][2], room_timers[1][2][3]);

}

if(room203Active == 1 && currentHour >= room_timers[1][3][0] &&

currentHour <= (room_timers[1][3][2] + 1)){

room2Lights = checkOnTime(room_timers[1][3][0], room_timers[1][3][1],

room_timers[1][3][2], room_timers[1][3][3]);

}

if(room2Lights == 1 && lightLevel[1] == 1){

lightOutput[1] = 2;

}

else {

lightOutput[1] = 0;

lightLevel[1] =0;

}

////////Room 3 (Bed 3) ////////////

if(room3MActive == 1 && currentHour >= room_timers[2][0][0] &&

currentHour <= (room_timers[2][0][2] + 1)){

room3Lights = checkOnTime(room_timers[2][0][0], room_timers[2][0][1],

room_timers[2][0][2], room_timers[2][0][3]);

}

if(room301Active == 1 && currentHour >= room_timers[2][1][0] &&

currentHour <= (room_timers[2][1][2] + 1)){

room3Lights = checkOnTime(room_timers[2][1][0], room_timers[2][1][1],

room_timers[2][1][2], room_timers[2][1][3]);

}

if(room302Active == 1 && currentHour >= room_timers[2][2][0] &&

currentHour <= (room_timers[2][2][2] + 1)){

room3Lights = checkOnTime(room_timers[2][2][0], room_timers[2][2][1],

room_timers[2][2][2], room_timers[2][2][3]);

}

if(room303Active == 1 && currentHour >= room_timers[2][3][0] &&

currentHour <= (room_timers[2][3][2] + 1)){

room3Lights = checkOnTime(room_timers[2][3][0], room_timers[2][3][1],

room_timers[2][3][2], room_timers[2][3][3]);

}

if(room3Lights == 1 && lightLevel[2] == 1){

lightOutput[2] = 4;

}

else {

lightOutput[2] = 0;

lightLevel[2] = 0;

}

////////Room 4 (living)/////////////////////

if(room4MActive == 1 && currentHour >= room_timers[3][0][0] &&

currentHour <= (room_timers[3][0][2] + 1)){

room4Lights = checkOnTime(room_timers[3][0][0], room_timers[3][0][1],

room_timers[3][0][2], room_timers[3][0][3]);

}

if(room401Active == 1 && currentHour >= room_timers[3][1][0] &&

currentHour <= (room_timers[3][1][2] + 1)){

room4Lights = checkOnTime(room_timers[3][1][0], room_timers[3][1][1],

room_timers[3][1][2], room_timers[3][1][3]);

}

if(room401Active == 1 && currentHour >= room_timers[3][2][0] &&

currentHour <= (room_timers[3][2][2] + 1)){

room4Lights = checkOnTime(room_timers[3][2][0], room_timers[3][2][1],

room_timers[3][2][2], room_timers[3][2][3]);

}

if(room401Active == 1 && currentHour >= room_timers[3][3][0] &&

currentHour <= (room_timers[3][3][2] + 1)){

room4Lights = checkOnTime(room_timers[3][3][0], room_timers[3][3][1],

room_timers[3][3][2], room_timers[3][3][3]);

}

if(room4Lights == 1 && lightLevel[3] == 1){

lightOutput[3] = 8;

}

else {

lightOutput[3] = 0;

lightLevel[3] = 0;

}

////////Room 5 (Bath 1)/////////////////////

if(room5MActive == 1 && currentHour >= room_timers[4][0][0] &&

currentHour <= (room_timers[4][0][2] + 1)){

room5Lights = checkOnTime(room_timers[4][0][0], room_timers[4][0][1],

room_timers[4][0][2], room_timers[4][0][3]);

}

if(room501Active == 1 && currentHour >= room_timers[4][1][0] &&

currentHour <= (room_timers[4][1][2] + 1)){

room5Lights = checkOnTime(room_timers[4][1][0], room_timers[4][1][1],

room_timers[4][1][2], room_timers[4][1][3]);

}

if(room5Lights == 1 && lightLevel[4] == 1){

lightOutput[4] = 16;

}

else {

lightOutput[4] = 0;

lightLevel[4] =0;

}

////////Room 6 (Bath 2)/////////////////////

if(room6MActive ==1 && currentHour >= room_timers[5][0][0] &&

currentHour <= (room_timers[5][0][2] + 1)){

room6Lights = checkOnTime(room_timers[5][0][0], room_timers[5][0][1],

room_timers[5][0][2], room_timers[5][0][3]);

}

if(room601Active == 1 && currentHour >= room_timers[5][1][0] &&

currentHour <= (room_timers[5][1][2] + 1)){

room6Lights = checkOnTime(room_timers[5][1][0], room_timers[5][1][1],

room_timers[5][1][2], room_timers[5][1][3]);

}

if(room6Lights == 1 && lightLevel[5] == 1){

lightOutput[5] = 32;

}

else {

lightOutput[5] = 0;

lightLevel[5] = 0;

}

////////Room 7 (Bath 3)/////////////////////

if(room7MActive == 1 && currentHour >= room_timers[6][0][0] &&

currentHour <= (room_timers[6][0][2])){

room7Lights = checkOnTime(room_timers[6][0][0], room_timers[6][0][1],

room_timers[6][0][2], room_timers[6][0][3]);

}

if(room701Active == 1 && currentHour >= room_timers[6][1][0] &&

currentHour <= (room_timers[6][1][2] + 1)){

room7Lights = checkOnTime(room_timers[6][1][0], room_timers[6][1][1],

room_timers[6][1][2], room_timers[6][1][3]);

}

if(room7Lights == 1 && lightLevel[6] == 1){

lightOutput[6] = 64;

}

else {

lightOutput[6] = 0;

lightLevel[6] = 0;

}

////////Room 8 (Bath 4)/////////////////////

if(room8MActive == 1 && currentHour >= room_timers[7][0][0] &&

currentHour <= (room_timers[7][0][2] + 1)){

room8Lights = checkOnTime(room_timers[7][0][0], room_timers[7][0][1],

room_timers[7][0][2], room_timers[7][0][3]);

}

if(room801Active == 1 && currentHour >= room_timers[7][1][0] &&

currentHour <= (room_timers[7][1][2] + 1)){

room8Lights = checkOnTime(room_timers[7][1][0], room_timers[7][1][1],

room_timers[7][1][2], room_timers[7][1][3]);

}

if(room8Lights == 1 && lightLevel[7] == 1){

lightOutput[7] = 128;

}

else {

lightOutput[7] = 0;

lightLevel[7] = 0;

}

////////Room 9 (kitchen)/////////////////////

if(room9MActive == 1 && currentHour >= room_timers[8][0][0] &&

currentHour <= (room_timers[8][0][2] + 1)){

room9Lights = checkOnTime(room_timers[8][0][0], room_timers[8][0][1],

room_timers[8][0][2], room_timers[8][0][3]);

}

if(room901Active == 1 && currentHour >= room_timers[8][1][0] &&

currentHour <= (room_timers[8][1][2] + 1)){

room9Lights = checkOnTime(room_timers[8][1][0], room_timers[8][1][1],

room_timers[8][1][2], room_timers[8][1][3]);

}

if(room9Lights == 1 && lightLevel[8] == 1){

lightOutput[8] = 256;

}

else {

lightOutput[8] = 0;

lightLevel[8] = 0;

}

////////Room 10 (corridor)/////////////////////

if(room10MActive == 1 && currentHour >= room_timers[9][0][0] &&

currentHour <= (room_timers[9][0][2] + 1)){

room10Lights = checkOnTime(room_timers[9][0][0], room_timers[9][0][1],

room_timers[9][0][2], room_timers[9][0][3]);

}

if(room1001Active == 1 && currentHour >= room_timers[9][1][0] &&

currentHour <= (room_timers[9][1][2] + 1)){

room9Lights = checkOnTime(room_timers[9][1][0], room_timers[9][1][1],

room_timers[9][1][2], room_timers[9][1][3]);

}

if(room10Lights == 1 && lightLevel[9] == 1){

lightOutput[9] = 512;

}

else {

lightOutput[9] = 0;

lightLevel[9] = 0;

}

////////Outside lights////////////////////

outsideOnTime = checkOnTime(17, 02, hourOutsideOff,

minuteOutsideOff); //function call to check time

//Serial.print("Timer: "); //debug only

Since we have updated the “Holiday light switching” part, we also need to update the menu points controlling the variables. There fore we move down to the selectMenu() function and find the first get_setTime() function call in the first sub menu.

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime( room1OnM[0], room1OnM[1],

room1OffM[0], room1OffM[1], 1);

return;

}

As we can see, we still pass on the variables we have just deleted. We need to match the passed on variables again with the new implemented 3-dimensional array. The last variable we pass on also changes to 0 to match the room count in the array. We also need to pass another variable to tell the system which timer we are addressing. In this case it is the first timer, so we pass another 0. The updated function call reads like this:

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timer[0][0][0], room_timer[0][0][1],

room_timer[0][0][2], room_timer[0][0][3],

0, 0);

return;

}

Since we extended the timers to 4 timers for the first four rooms, we also need to add the timers to the menu itself. Let's have a quick look at the beginning of the first submenu and add a couple of statements there. Here is the complete first sub menu with all changes made:

if(menuOption == 6) return; //and menu option is 6 return (not used)

if(menuOption == 7){ //and menu option is 7 (room 1)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 8){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 9){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[0] = get_delay(9, 1, dBed1);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room1MActive = get_offon(10, 1, room1MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timer[0][0][0], room_timer[0][0][1],

room_timer[0][0][2], room_timer[0][0][3],

0, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room1O1Active = get_offon(11, 1, room1O1Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timer[0][1][0], room_timer[0][1][1],

room_timer[0][1][2], room_timer[0][1][3],

0, 1);

return;

}

if(submenu == 6){ //and submenu is 6

//call the function get_offon() to change the setting

room102Active = get_offon(12, 1, room102Active);

return;

}

if(submenu == 7){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timer[0][2][0], room_timer[0][2][1],

room_timer[0][2][2], room_timer[0][2][3],

0, 2);

return;

}

if(submenu == 8){ //and submenu is 6

//call the function get_offon() to change the setting

room103Active = get_offon(25, 1, room103Active);

return;

}

if(submenu == 9){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timer[0][3][0], room_timer[0][3][1],

room_timer[0][3][2], room_timer[0][3][3],

0, 3);

return;

}

}

}

} //submenu end

Just adding the sub menu points and matching the variables for the time is pretty straight forward again. If you have a closer look at the “ room103Active = get_offon(25, 1, room103Active);” function call, there you find as first variable a “25”. Here we needed to add another info text in the program memory and not to rewrite the whole table and plenty of other statements, I just added it to the end of the message table in the declaration part under “menu and user interface. While we are back at this section, we also need to update the amount of submenu points.


///////////////////Menu and user interface/////////////////////////////////

///////////////////////////////////////////////////////////////////////////

const byte btnMenu = 1; //defining the menu button – moves through the menu

const byte btnSearch = 2; //defining the search button – moves through values

const byte btnSelect = 3; //defining the select button – selects a menu or a value

const byte btnNone = 0; //defining the non button pressed var

int act_key_in = 0; //var holding the key related sensor reading

byte menuOption = 0; //var to count current menu option

const byte menuOptions = 20; //available menu options

byte submenu = 0; //var to count current submenu option

//>>>>>>>>>>>>>Update to submenus = 9 in the line below<<<<<<<<<<<<<<

const byte submenus = 9; //available submenu options

char buffer_M[20]; //var holding the menu strings retrieved from

//the program memory

//Storing some menu messages in the program memory

prog_char msg_0[] PROGMEM = "Not Used";

prog_char msg_1[] PROGMEM = "Saving....";

prog_char msg_2[] PROGMEM = "Setup mode";

prog_char msg_3[] PROGMEM = "Starting....";

prog_char msg_4[] PROGMEM = "RMU 1.2.9";

prog_char msg_5[] PROGMEM = "Weekday";

prog_char msg_6[] PROGMEM = "On TIMER Off";

prog_char msg_7[] PROGMEM = "Off ";

prog_char msg_8[] PROGMEM = "Active";

prog_char msg_9[] PROGMEM = "PIR Delay R";

prog_char msg_10[] PROGMEM = "T1 On/Off R";

prog_char msg_11[] PROGMEM = "T2 On/Off R";

prog_char msg_12[] PROGMEM = "T3 On/Off R";

prog_char msg_13[] PROGMEM = "ADJ Hour On";

prog_char msg_14[] PROGMEM = "ADJ Minute On";

prog_char msg_15[] PROGMEM = "ADJ Hour Off";

prog_char msg_16[] PROGMEM = "ADJ Minute Off";

prog_char msg_17[] PROGMEM = "Set Sensitivity";

prog_char msg_18[] PROGMEM = "Set photocell R";

prog_char msg_19[] PROGMEM = "Set photocell O";

prog_char msg_20[] PROGMEM = "ADJ Time Minute";

prog_char msg_21[] PROGMEM = "ADJ Time Hour";

prog_char msg_22[] PROGMEM = "ADJ Date Day";

prog_char msg_23[] PROGMEM = "ADJ Date Month";

prog_char msg_24[] PROGMEM = "ADJ Date Year";

//>>>>>>>>>>>>>>Add the line below<<<<<<<<<<<<<

prog_char msg_25[] PROGMEM = "T4 On/Off R";

//Creating the table for the stored menu messages

PROGMEM const char *msg_table[] = {

msg_0,

msg_1,

msg_2,

msg_3,

msg_4,

msg_5,

msg_6,

msg_7,

msg_8,

msg_9,

msg_10,

msg_11,

msg_12,

msg_13,

msg_14,

msg_15,

msg_16,

msg_17,

msg_18,

msg_19,

msg_20,

msg_21,

msg_22,

msg_23,

msg_24,

//>>>>>>>>>>>>>Add below<<<<<<<<<<<<<<

msg_25

};

We have to do now the above described alterations with all the sub menus. I added below the complete selectMenu() function with all the alterations.


void selectMenu(){

//Serial.println("SelectMenu");

byte button = 0; //var holding the button value

byte subButton = 0; //var holding the subButton value

menuOption = 1; //current menu option

lcd.clear(); //clear screen

//print the retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[0]))));

while(menuOption <= menuOptions){ //loop through menu options

button = read_act_buttons(); //check if button was pressed

if(button == btnMenu){ //if it was btn menu

menuOption++; //add 1 to menu option

if(menuOption == 2){ //if it's menu option 2

lcd.clear(); //clear display

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[1]))));

}

if(menuOption == 3){ //if it's menu option 3

lcd.clear(); //clear display

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[2]))));

}

if(menuOption == 4){ //if it's menu option 4

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[3]))));

lcd.setCursor(0, 1); //set cursor to row 2 column 1

//print retrieved message srting

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(msg_table[0]))));

}

if(menuOption == 5){ //if it's menu option 5

lcd.clear(); //clear display

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[4]))));

}

if(menuOption == 6){ //if it's menu option 6

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[5]))));

lcd.setCursor(0, 1); //set cursor to row 2 column 1

//print retrieved message string

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(menuOption == 7){ //if it's menu option 7

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[6]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 8){ //if it's menu option 8

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[7]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 9){ //if it's menu option 9

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[8]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 10){ //if it's menu option 10

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[9]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 11){ //if it's menu option 12

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[10]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 12){ //if it's menu option 13

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[11]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 13){ //if it's menu option 14

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[12]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 14){ //if it's menu option 15

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[13]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 15){ //if it's menu option 16

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[14]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 16){ //if it's menu option 17

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[15]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 17){ //if it's menu option 18

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[16]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 18){ //if it's menu option 19

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[17]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 19){ //if it's menu option 20

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[18]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

if(menuOption == 20){ //if it's menu option 21

lcd.clear(); //clear lcd

//print retrieved string on lcd

lcd.print(strcpy_P(buffer_M, (char*)pgm_read_word(&(menu_table[19]))));

lcd.setCursor(15, 0); //set cursor to row 2 column 1

//print retrieved message string

lcd.write(pgm_read_byte(&char_table[0]));

}

}

if(button == btnSelect){ //if the select button is pressed

if(menuOption == 1){ //and menu option is 1

adjust_date_time(); //go to adjust date and time

return;

}

if(menuOption == 2){ //and menu option is 2

sensitivity = get_Timer(17, sensitivity, 0, 1000); //go to function

return;

}

if(menuOption == 3){ //and menu option is 3

photoCellCutOff = get_Timer(18, photoCellCutOff, 0, 1024); //go to function

return;

}

if(menuOption == 4) return; //and menu option is 4 return (not used)

if(menuOption == 5){ //and menu option is 5

photoOutsideOff = get_Timer(19, photoOutsideOff, 0, 1024); //go to function

return;

}

if(menuOption == 6) return; //and menu option is 6 return (not used)

if(menuOption == 7){ //and menu option is 7 (room 1)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 8){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

if(submenu == 9){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[5])); //printing assigned room number 1

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[0] = get_delay(9, 1, dBed1);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room1MActive = get_offon(10, 1, room1MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[0][0][0], room_timers[0][0][1],

room_timers[0][0][2], room_timers[0][0][3],

0, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room1O1Active = get_offon(11, 1, room1O1Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[0][1][0], room_timers[0][1][1],

room_timers[0][1][2], room_timers[0][1][3],

0, 1);

return;

}

if(submenu == 6){ //and submenu is 6

//call the function get_offon() to change the setting

room102Active = get_offon(12, 1, room102Active);

return;

}

if(submenu == 7){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[0][2][0], room_timers[0][2][1],

room_timers[0][2][2], room_timers[0][2][3],

0, 2);

return;

}

if(submenu == 8){ //and submenu is 6

//call the function get_offon() to change the setting

room103Active = get_offon(25, 1, room103Active);

return;

}

if(submenu == 9){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[0][3][0], room_timers[0][3][1],

room_timers[0][3][2], room_timers[0][3][3],

0, 3);

return;

}

}

}

} //submenu end

if(menuOption == 8){ //and menu option is 8 (room 2)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 8){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

if(submenu == 9){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[6])); //printing assigned room number 2

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[1] = get_delay(9, 2, dBed2);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room2MActive = get_offon(10, 2, room2MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[1][0][0], room_timers[1][0][1],

room_timers[1][0][2], room_timers[1][0][3],

1, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room201Active = get_offon(11, 2, room201Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[1][1][0], room_timers[1][1][1],

room_timers[1][1][2], room_timers[1][1][3],

1, 1);

return;

}

if(submenu == 6){ //and submenu is 6

//call the function get_offon() to change the setting

room202Active = get_offon(12, 2, room202Active);

return;

}

if(submenu == 7){ //and submenu is 7

//call the function get_setTime() to change timer 2

get_setTime(room_timers[1][2][0], room_timers[1][2][1],

room_timers[1][2][2], room_timers[1][2][3],

1, 2);

return;

}

if(submenu == 8){ //and submenu is 8

//call the function get_offon() to change the setting

room203Active = get_offon(25, 2, room203Active);

return;

}

if(submenu == 9){ //and submenu is 9

//call the function get_setTime() to change timer 2

get_setTime(room_timers[1][3][0], room_timers[1][3][1],

room_timers[1][3][2], room_timers[1][3][3],

1, 3);

return;

}

}

}

} //submenu end

if(menuOption == 9){ //and menu option is 9 (room 3)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[7])); //printing assigned room number 3

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[2] = get_delay(9, 3, dBed3);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room3MActive = get_offon(10, 3, room3MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[2][0][0], room_timers[2][0][1],

room_timers[2][0][2], room_timers[2][0][3],

2, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room301Active = get_offon(11, 3, room301Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[2][1][0], room_timers[2][1][1],

room_timers[2][1][2], room_timers[2][1][3],

2, 1);

return;

}

if(submenu == 6){ //and submenu is 6

//call the function get_offon() to change the setting

room302Active = get_offon(12, 3, room302Active);

return;

}

if(submenu == 7){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[2][2][0], room_timers[2][2][1],

room_timers[2][2][2], room_timers[2][2][3],

2, 2);

return;

}

if(submenu == 8){ //and submenu is 6

//call the function get_offon() to change the setting

room303Active = get_offon(25, 3, room302Active);

return;

}

if(submenu == 9){ //and submenu == 7

//call function get_setTime() to change timer 3

get_setTime(room_timers[2][3][0], room_timers[2][3][1],

room_timers[2][3][2], room_timers[2][3][3],

2, 3);

return;

}

}

}

} //submenu end

if(menuOption == 10){ //and menu option is 9 (room 4)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 8){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

if(submenu == 9){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[8])); //printing assigned room number 4

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[3] = get_delay(9, 4, dLiving);

return;

}

if(submenu == 2) { //and submenu is 2

//call the function get_offon() to change the setting

room4MActive = get_offon(10, 4, room4MActive);

return;

}

if(submenu == 3){ //and submenu == 3

//call function get_setTime() to change timer 0

get_setTime(room_timers[3][0][0], room_timers[3][0][1],

room_timers[3][0][2], room_timers[3][0][3],

3, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room401Active = get_offon(11, 4, room401Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 1

get_setTime(room_timers[3][1][0], room_timers[3][1][1],

room_timers[3][1][2], room_timers[3][1][3],

3, 1);

return;

}

if(submenu == 6){ //and submenu is 6

//call the function get_offon() to change the setting

room402Active = get_offon(12, 4, room402Active);

return;

}

if(submenu == 7){ //and submenu is 7

//call the function get_setTime() to change timer 3

get_setTime(room_timers[3][2][0], room_timers[3][2][1],

room_timers[3][2][2], room_timers[3][2][3],

3, 2);

return;

}

if(submenu == 8){ //and submenu is 8

//call the function get_offon() to change the setting

room403Active = get_offon(25, 4, room403Active);

return;

}

if(submenu == 9){ //and submenu is 9

//call the function get_setTime() to change timer 1

get_setTime(room_timers[3][3][0], room_timers[3][3][1],

room_timers[3][3][2], room_timers[3][3][3],

3, 3);

return;

}

}

}

} //submenu end

if(menuOption == 11){ //and menu option is 11 (room 5)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[9])); //printing assigned room number 5

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[4] = get_delay(9, 5, dBath1);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room5MActive = get_offon(10, 5, room5MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[4][0][0], room_timers[4][0][1],

room_timers[4][0][2], room_timers[4][0][3],

4, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room501Active = get_offon(11, 5, room501Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[4][1][0], room_timers[4][1][1],

room_timers[4][1][2], room_timers[4][1][3],

4, 1);

return;

}

if(submenu == 6)return;

if(submenu == 7)return;

if(submenu == 8)return;

if(submenu == 9)return;

}

}

} //submenu end

if(menuOption == 12){ //and menu option is 12 (room 6)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[10])); //printing assigned room number 6

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[5] = get_delay(9, 6, dBath2);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room6MActive = get_offon(10, 6, room6MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[5][0][0], room_timers[5][0][1],

room_timers[5][0][2], room_timers[5][0][3],

5, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room601Active = get_offon(11, 6, room601Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[5][1][0], room_timers[5][1][1],

room_timers[5][1][2], room_timers[5][1][3],

5, 1);

return;

}

if(submenu == 6)return;

if(submenu == 7)return;

if(submenu == 8)return;

if(submenu == 9)return;

}

}

} //submenu end

if(menuOption == 13){ //and menu option is 13 (room 7)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[11])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[6] = get_delay(9, 7, dBath3);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room7MActive = get_offon(10, 7, room7MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[6][0][0], room_timers[6][0][1],

room_timers[6][0][2], room_timers[6][0][3],

6, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room701Active = get_offon(11, 7, room701Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[6][1][0], room_timers[6][1][1],

room_timers[6][1][2], room_timers[6][1][3],

6, 1);

return;

}

if(submenu == 6)return;

if(submenu == 7)return;

if(submenu == 8)return;

if(submenu == 9)return;

}

}

} //submenu end

if(menuOption == 14){ //and menu option is 14 (room 8)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[12])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[7] = get_delay(9, 8, dBath4);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room8MActive = get_offon(10, 8, room8MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[7][0][0], room_timers[7][0][1],

room_timers[7][0][2], room_timers[7][0][3],

7, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room801Active = get_offon(11, 8, room801Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[7][1][0], room_timers[7][1][1],

room_timers[7][1][2], room_timers[7][1][3],

7, 1);

return;

}

if(submenu == 6)return;

if(submenu == 7)return;

if(submenu == 8)return;

if(submenu == 9)return;

}

}

} //submenu end

if(menuOption == 15){ //and menu option is 15 (room 9)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[7]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[8]))));

lcd.write(pgm_read_byte(&char_table[13])); //printing assigned room number 7

lcd.setCursor(0, 1);

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[8] = get_delay(9, 9, dKitchen);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room9MActive = get_offon(10, 9, room9MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[8][0][0], room_timers[8][0][1],

room_timers[8][0][2], room_timers[8][0][3],

8, 0);

return;

}

if(submenu == 4){ //and submenu is 4

//call the function get_offon() to change the setting

room901Active = get_offon(11, 9, room901Active);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 2

get_setTime(room_timers[8][1][0], room_timers[8][1][1],

room_timers[8][1][2], room_timers[8][1][3],

8, 0);

return;

}

if(submenu == 6)return;

if(submenu == 7)return;

if(submenu == 8)return;

if(submenu == 9)return;

}

}

} //submenu end

if(menuOption == 16){ //and menu option is 16 (room 10)

subButton = 0; //resetting the button var

submenu = 1; //submenu counter

lcd.clear(); //clear screen

//retrieving and printing first sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[0]))));

lcd.print("10"); //printing assigned room number 10

while(submenu < submenus){ //loop through the sub menu points

subButton = read_act_buttons(); //checking for pressed buttons

if(subButton == btnMenu){ //if button Menu was pressed

submenu++; //add 1 - move to the next sub menu point

if(submenu == 2){ //if we are at sub menu 2

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[1]))));

lcd.print("10"); //printing assigned room number 10

}

if(submenu == 3){ //if we are at sub menu 3

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[2]))));

lcd.print("10"); //printing assigned room number 10

}

if(submenu == 4){ //if we are at sub menu 4

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[3]))));

lcd.print("10"); //printing assigned room number 10

}

if(submenu == 5){ //if we are at sub menu 5

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[4]))));

lcd.print("10"); //printing assigned room number 10

}

if(submenu == 6){ //if we are at sub menu 6

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 7){ //if we are at sub menu 7

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 8){ //if we are at sub menu 8

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[5]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

if(submenu == 9){ //if we are at sub menu 9

lcd.clear();

//retrieve and print second sub menu point

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(submenu_table[6]))));

lcd.print("10"); //printing assigned room number 10

lcd.setCursor(0, 1); //set cursor second row, first column

lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0])))); //print NOT USED

}

}

if(subButton == btnSelect){ //if we pressed btnSelect

if(submenu == 1){ //and submenu is 1

//call the function get_delay() to change the setting

delayTime[9] = get_delay(9, 10, dCorridor);

return;

}

if(submenu == 2){ //and sub menu is 2

//call the function get_offon to change the setting

room10MActive = get_offon(10, 10, room10MActive);

return;

}

if(submenu == 3){ //and submenu is 3

//call the function get_setTime() to change timer 1

get_setTime(room_timers[9][0][0], room_timers[9][0][1],

room_timers[9][0][2], room_timers[9][0][3],

9, 0);

return;

}

if(submenu == 4){ //and sub menu is 4

//call the function get_offon to change the setting

room10MActive = get_offon(11, 10, room10MActive);

return;

}

if(submenu == 5){ //and submenu is 5

//call the function get_setTime() to change timer 1

get_setTime(room_timers[9][1][0], room_timers[9][1][1],

room_timers[9][1][2], room_timers[9][1][3],

9, 1);

return;

}

if(submenu == 6) return;

if(submenu == 7) return;

if(submenu == 8) return;

if(submenu == 9) return;

}

}

} //submenu end

}

}

}

As today's final, we change the get_setTime() function to fit the new function calls in the sub menus.

byte get_setTime(char timeText[], byte onTimeH,

byte onTimeM, byte offTimeH,

byte offTimeM, byte room){

changes to

byte get_setTime( byte onTimeH, byte onTimeM, byte offTimeH,

byte offTimeM, byte room, byte timer){

Than we delete the complete part where we pass the updated variables back:


//This part to DELETE all!!

if(room == 1){

room1OnM[0] = onTimeH;

room1OnM[1] = onTimeM;

room1OffM[0] = offTimeH;

room1OffM[1] = offTimeM;

}

if(room == 2){

room1On1[0] = onTimeH;

room1On1[1] = onTimeM;

room1Off1[0] = offTimeH;

room1Off1[1] = offTimeM;

}

if(room == 3){

room1On2[0] = onTimeH;

room1On2[1] = onTimeM;

room1Off2[0] = offTimeH;

room1Off2[1] = offTimeM;

}

if(room = 11){

room2OnM[0] = onTimeH;

room2OnM[1] = onTimeM;

room2OffM[0] = offTimeH;

room2OffM[1] = offTimeM;

}

if(room = 12){

room2On1[0] = onTimeH;

room2On1[1] = onTimeM;

room2Off1[0] = offTimeH;

room2Off1[1] = offTimeM;

}

and we replace it with:


room_timers[room][timer][0] = onTimeH;

room_timers[room][timer][1] = onTimeM;

room_timers[room][timer][2] = offTimeH;

room_timers[room][timer][3] = offTimeM;

The next task on the to do list is getting the sub menu  into a function not to repeat the same bit of code 10 times as we are doing in the moment.

No comments:

Post a Comment