To code in the checks for the AC-units
we go again all the way down to the end of our main loop:
else if(switchState[13] == 0 &&
lightStatus[9] == 1) { //if no PIR was activated and
//the lights are on
Serial.println("We are
checking the timer"); //Debug only
currentTime = millis(); //setting time reference
endTime = currentTime -
roomTimer[9]; //calculating the inactive time
if(endTime >= delayTime[9]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[9] = 0;
//switching off the lights
lightStatus[9] = 0;
//resetting the light status
roomTimer[9] = 0;
//resetting the room timer
}
}
//>>>>>>>>>>We
start again adding here<<<<<<<<<<<<<<<<
if(switchState[14] == 1 &&
lightStatus[14] == 1){ //Checking if read switches are
//activated and the master
//relay is on, AC room 1 (bed1)
lightOutput[10] = 1024;
//providing the ability to
//switch on the AC
lightStatus[10] = 1;
//setting the light (AC) status
roomTimer[10] = millis();
//setting the timer
}
else if(switchState[14] == 0 &&
lightStatus[14] == 1){ //if a door is opened and the master
//relay is on
currentTime = millis(); //setting time reference
endTime = currentTime -
roomTimer[10]; //calculating the inactive time
if(endTime >= delayTime[10]){
//comparing inactive time with
//delay time
lightOutput[10] = 0; //canceling ability to switch on the
//AC
lightStatus[10] = 0; //resetting the light (AC) status
roomTimer[10] = 0;
//resetting the timer
}
}
if(switchState[15] == 1 &&
lightStatus[14] == 1){ //Checking if read switches
//are activated and the master
//relay is on AC room 2 (bed2)
lightOutput[11] = 2048;
//providing the ability to
//switch on the AC
lightStatus[11] = 1;
//setting the light (AC) status
roomTimer[11] = millis();
//setting the timer
}
else if(switchState[15] == 0 &&
lightStatus[14] == 1){ //if a door is opened and the master
//relay is on
currentTime = millis();
//setting time reference
endTime = currentTime -
roomTimer[11]; //calculating the inactive time
if(endTime >= delayTime[11]){ //comparing inactive time with
//delay time
lightOutput[11] = 0;
//canceling ability to switch on the
//AC
lightStatus[11] = 0;
//resetting the light (AC) status
roomTimer[11] = 0;
//resetting the timer
}
}
if(switchState[16] == 1 &&
lightStatus[14] == 1){ //Checking if read switches are
//activated and the master
//relay is on AC room 3 (bed3)
lightOutput[12] = 4096;
//providing the ability to
//switch on the AC
lightStatus[12] = 1;
//setting the light (AC) status
roomTimer[12] = millis();
//setting the timer
}
else if(switchState[16] == 0 &&
lightStatus[14] == 1){ //if a door is opened and the master
//relay is on
currentTime = millis();
//setting time reference
endTime = currentTime -
roomTimer[12]; //calculating the inactive time
if(endTime >= delayTime[12]){
//comparing inactive time with
//delay time
lightOutput[12] = 0;
//canceling ability to switch on the
//AC
lightStatus[12] = 0;
//resetting the light (AC) status
roomTimer[12] = 0;
//resetting the timer
}
}
if(switchState[17] == 1 &&
lightStatus[14] == 1){ //Checking if readswitches are
activated
//and the master relay is on AC room 4
//living
lightOutput[13] = 8192;
//providing the ability to
//switch on the AC
lightStatus[13] = 1;
//setting the light (AC) status
roomTimer[13] = millis();
//setting the timer
}
else if(switchState[17] == 0 &&
lightStatus[14] == 1){ //if a door is opened and the master
//relay is on
currentTime = millis();
//setting time reference
endTime = currentTime -
roomTimer[13]; //calculating the inactive time
if(endTime >= delayTime[13]){
//comparing inactive time with
//delay time
lightOutput[13] = 0;
//canceling ability to switch on the
//AC
lightStatus[13] = 0;
//resetting the light (AC) status
roomTimer[13] = 0;
//resetting the timer
}
}
}
//>>>>>>>>>>>>>>End
of the main loop<<<<<<<<<<<<<<
To control the AC's we use the same
code as for controlling the standard light output without priority.
In praxis we only connect a read switch to the input and not a PIR.
If you like to try the new implemented code, it will not work until
the next chapter when we code the master relay since we are checking
if the master relay is switched on. The array “lightStatus[14]”
will be holding the status of the master relay which is still set to
0.
No comments:
Post a Comment