Translate

Tuesday, 3 June 2014

Room Management System – Bug fix to outside lighting


Since I added the single variables controlling the outside lights into the array holding all the on and off times for the lights, the outside lights wouldn't come on any more. Banging my head on the desk for a day and I finally found the reason. I know, I should take a couple of extra lessons in maths. It's the 0, which caught me again. In all the place holders the number 14 in the arrays is the control for the master relay and the master relay is not addressed in any light controls so I always forget about it. The outside lights are no 15 and that's again my number. Looking into the timer_active array and the room_timers array there is no space for the master relay since we do not address it in general room lighting. Simply, the space 14 was missing and the timers for the outside lights became the 15 space in the array which is again the no 14 because arrays start counting with 0. To cut an ongoing story short, there is a simple solution for this problem:

Lets go to the timer_active array pretty much at the beginning of the declaration part:


byte timer_active[16][4] = { //<<<<<<<<<<<timer_active[15 ][4] changes to timer_active[16][4]

{1, 1, 1, 0}, //room 0 timers 0 to 3

{1, 1, 0, 0}, //room 1 timers 0 to 3

{1, 1, 1, 1}, //room 2 timers 0 to 3

{0, 1, 0, 0}, //room 3 timers 0 to 3

{1, 1, 2, 2}, //room 4 timers 0 to 3

{1, 1, 2, 2}, //room 5 timers 0 to 3

{1, 1, 2, 2}, //room 6 timers 0 to 3

{1, 0, 2, 2}, //room 7 timers 0 to 3

{1, 1, 2, 2}, //room 8 timers 0 to 3

{0, 0, 2, 2}, //room 9 timers 0 to 3

{1, 1, 1, 0}, //room 0 AC timers 0 to 3

{1, 1, 1, 0}, //room 1 AC timers 0 to 3

{1, 1, 1, 0}, //room 2 AC timers 0 to 3

{1, 1, 2, 0}, //room 3 AC timers 0 to 3

//>>>>>>>>>>>>Insert the line below<<<<<<<<<<<<<

{2, 2, 2, 2}, //Dummy timer

{0, 1, 2, 2} //outside lighting

};

Here we have to update the numbers in the initialisation and I just added a set and set it to 2 for not used not to effect the operation of the master relay.

Now we insert a dummy timer into the room_timers array in place 15, placeholder [14].


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

byte room_timers[16][4][4] = { //<<<<<<room_timers[15][4][4] changes to room_timers[16][4][4]

{

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

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

{21, 5, 21, 15}, //room 0 timer 2

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

},

{

{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

},

{

{19, 30, 22, 0}, //room 0 AC timer 1

{19, 30, 5, 30}, //room 0 AC timer 2

{19, 30, 22, 0}, //room 0 AC timer 3

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

},

{

{19, 30, 22, 0}, //room 1 AC timer 1

{19, 30, 5, 30}, //room 1 AC timer 2

{19, 30, 22, 0}, //room 1 AC timer 3

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

},

{

{21, 30, 1, 0}, //room 2 AC timer 1

{21, 30, 6, 0}, //room 2 AC timer 2

{21, 30, 1, 0}, //room 2 AC timer 3

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

},

{

{13, 0, 20, 0}, //room 3 AC timer 1

{5, 0, 23, 59}, //room 3 AC timer 2

{6, 0, 20, 0}, //room 3 AC timer 3

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

},

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

{

{0, 0, 0, 0}, //Dummy timer not used

{0, 0, 0, 0},

{0, 0, 0, 0},

{0, 0, 0, 0}

},

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

{

{0, 0, 0, 0}, //outside lights timer 1

{17, 3, 23, 59}, //outside lights timer 2

{0, 0, 0, 0}, //outside lights timer 3

{0, 0, 0, 0} //outside lights timer 4

}

};

Now we move down int the main loop into the outside lights section. There we have to add a break command in the loop soon as the on time check returns a 1 not to overwrite the on command with a following 0:


for(int i=0; i<4; i++){

if(timer_active[15][i] == 1){

roomLight[15] = checkOnTime(room_timers[15][i][0], room_timers[15][i][1],

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

}

if(roomLight[15] == 1) break; //<<<<<<<<<<<<<ADD the break if a 1 is returned

}

if(roomLight[15] == 1 && lightLevel[15] == 1){

lightOutput[15] = outputValues[15];

}

else{

lightOutput[15] = 0;

lightLevel[15] = 0;

}

No comments:

Post a Comment