As promised, today we look at the code
we need for all the rooms without a priority button. Again, we start
at the end of our main loop:
else if(switchState[7] == 1 &&
lightStatus[3] == 1) { //if priority is activated and the
//lights are
on
Serial.println("Priority
switch activated, switching off the lights"); //debug only
lightOutput[3] = 0;
//switching off the
lights
lightStatus[3] = 0;
//resetting the light
status
roomTimer[3] = 0;
//resetting the room timer
priorityStatus[3] = 1;
//setting the priority
status for
//bed 2
}
else if(switchState[7] == 1 &&
lightStatus[3] == 0) { //if priority is activated and the
//lights are
off
Serial.println("Priority
switch off, switching the light back to normal"); //debug only
lightOutput[3] = 8;
//switching ion the
lights
lightStatus[3] = 1;
//setting the light
status
roomTimer[3] = millis();
//setting the room timer
priorityStatus[3] = 0;
//resetting the priority
status
}
//>>>>>>>>>>>>>>>We
start coding here<<<<<<<<<<<<<<<<<<
if(switchState[8] == 1) {
//checking S9 PIR of bathroom 1
//(room 5)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[4] = 16;
//switching on the lights
lightStatus[4] = 1;
//setting the light status
roomTimer[4] = millis();
//setting the room timer
}
else if(switchState[8] == 0 &&
lightStatus[4] == 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[4]; //calculating the inactive time
if(endTime >= delayTime[4]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[4] = 0; //switching off the lights
lightStatus[4] = 0;
//resetting the light status
roomTimer[4] = 0;
//resetting the room timer
}
}
if(switchState[9] == 1) {
//checking S10 PIR of bathroom 2
//(room 6)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[5] = 32;
//switching on the lights
lightStatus[5] = 1;
//setting the light status
roomTimer[5] = millis();
//setting the room timer
}
else if(switchState[9] == 0 &&
lightStatus[5] == 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[5]; //calculating the inactive time
if(endTime >= delayTime[5]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[5] = 0;
//switching off the lights
lightStatus[5] = 0;
//resetting the light status
roomTimer[5] = 0;
//resetting the room timer
}
}
if(switchState[10] == 1) {
//checking S11 PIR of bathroom 3
//(room 7)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[6] = 64;
//switching on the lights
lightStatus[6] = 1;
//setting the light status
roomTimer[6] = millis();
//setting the room timer
}
else if(switchState[10] == 0 &&
lightStatus[6] == 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[6]; //calculating the inactive time
if(endTime >= delayTime[6]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[6] = 0;
//switching off the lights
lightStatus[6] = 0;
//resetting the light status
roomTimer[6] = 0;
//resetting the room timer
}
}
if(switchState[11] == 1) {
//checking S12 PIR of bathroom 4
//(room 8)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[7] = 128;
//switching on the lights
lightStatus[7] = 1;
//setting the light status
roomTimer[7] = millis();
//setting the room timer
}
else if(switchState[11] == 0 &&
lightStatus[7] == 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[7]; //calculating the inactive time
if(endTime >= delayTime[7]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[7] = 0;
//switching off the lights
lightStatus[7] = 0;
//resetting the light status
roomTimer[7] = 0;
//resetting the room timer
}
}
if(switchState[12] == 1) {
//checking S13 PIR of kitchen
//(room 9)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[8] = 256;
//switching on the lights
lightStatus[8] = 1;
//setting the light status
roomTimer[8] = millis();
//setting the room timer
}
else if(switchState[12] == 0 &&
lightStatus[8] == 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[8]; //calculating the inactive time
if(endTime >= delayTime[8]) {
//comparing inactive time with
//delay time
Serial.println("We are
switching off the lights"); //debug only
lightOutput[8] = 0;
//switching off the lights
lightStatus[8] = 0;
//resetting the light status
roomTimer[8] = 0;
//resetting the room timer
}
}
if(switchState[13] == 1) {
//checking S14 PIR of Corridor
//(room 10)
Serial.println("We switch on
the lights"); //Debug only
lightOutput[9] = 512;
//switching on the lights
lightStatus[9] = 1; //setting the light status
roomTimer[9] = millis();
//setting the room timer
}
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
}
}
}
//>>>>>>>>>>>>>>>>End
of main loop<<<<<<<<<<<<<<<<<<<
The code for the rooms without the
priority button is nearly the same as with. We only cut the parts
where we check if a priority was set.
In the next chapter we will be taking care of the 4 AC-units.
If everything is working, start commenting out the Serial.print statements which are marked as "Debug only" since this statements start taking off a lot of the microchips memory.
If everything is working, start commenting out the Serial.print statements which are marked as "Debug only" since this statements start taking off a lot of the microchips memory.
No comments:
Post a Comment