hi all,
So, i am trying to finish a little project but ran into an issues with 2 toggle switches and not sure how to solve it.
So here is what i have...
2 single throw toggle switches.
Switch one (nightModeSwitchControl) which when HIGH turns off all my 7 segments displays.
Switch two (powerSavingSwitch) which when high activates statement "powerSaving();" which then turns off all 7 segment displays at a certain time during the night.
this is the code i have:
void nightModeSwitchControl() {
if(digitalRead(nightModeSwitch) == HIGH) {
turnDisplaysOff();
}
else {
turnDisplaysOn();
}
}
void powerSavingSwitch() {
if(digitalRead(powerSaveSwitch) == HIGH) {
digitalWrite(LED_POWERSAVING, HIGH);
powerSaving();
}
else {
digitalWrite(LED_POWERSAVING, LOW);
}
}
void powerSaving(){
// turn off displays at 2am
if (hour() == 02 && minute() == 00) {
turnDisplaysOff();
} else if
(hour() == 06 && minute() == 00)
turnDisplaysOn();
}
Now, how this should work is, i toggle switch two and activate power saving mode. This works ok BUT, as switch one has a contradictory statement and is almost always in LOW state which in turn turns the displays ON, contradicts the power saving statement that turns the displays OFF. So when power saving kicks in, displays try to turn OFF and then flicker as "night model switch" is in displays ON state.
If i turn off the power saving switch, night mode switch works like a charm, it toggles the displays ON and OFF as it should.
What i would like to have is a "power saving" option to turn OFF displays regardless in what state the "night mode" switch is and ideally, when the power saving is on and displays turned off, to be able to somehow turn ON the displays if needed.
So if power saving turns the displays OFF at 2am and keeps them OFF until 6am, i would like to be able to turn ON displays at any time between 2am and 6am by either disabling the power saving or by manipulating night mode switch...
I hope my explanation is clear.
Any help would be highly appreciated.
Many thanks,
Alek

