So i actually did this often and it worked before. But somehow i forgot and can't seem to work out whats missing...
Heres the Code
boolean Power = false;
switch (Second)
{
case 0 ... 7:
if (Power = true)
{
Serial.println("Lights OFF");
Power = false;
};
break;
case 8 ... 40:
if (Power = false)
{
Serial.println("Lights On");
Power = true;
};
break;
case 41 ... 59:
if (Power = true)
{
Serial.println("Lights OFF");
Power = false;
};
break;
}
Ive cuz out the rest of the Code cause its not relevant for this Problem. The Numbers are Seconds ranging from 0-59 (being pulled from a RTC and later replaced by Hours).
However the Serial Monitor sends Lights OFF/ON every time
I just want this function to Send the text to the Serial Monitor once it goes from 7 to 8 and from 40 to 41.
Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whetherx is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true.
This is because C++ evaluates the statement if (x=10) as follows: 10 is assigned to x (remember that the single equal sign is the (assignment operator)), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. Consequently, if (x = 10) will always evaluate to TRUE, which is not the desired result when using an 'if' statement. Additionally, the variable x will be set to 10, which is also not a desired action.