in the following line, I see an equals sign, then a space and then an exclamation point. What does that mean? I found that the reverse version without the space (!=) means "not equal to"
ledAstate = ! ledAstate;
in the following line, I see an equals sign, then a space and then an exclamation point. What does that mean? I found that the reverse version without the space (!=) means "not equal to"
ledAstate = ! ledAstate;
It's the logical NOT operation.
AWOL:
It's the logical NOT operation.
I gotcha. I at least understand the logic side of it. If used in an "if" statement, what is it actually doing? What is the outcome of using it?
For example...
if (currentMillis - prevLedAMillis >= ledAInterval) {
prevLedAMillis += ledAInterval;
ledAstate = ! ledAstate;
You're not using it in an if statement, you're using it in a conditional code block.
It inverts its operand, ledAstate, and assigns the result to ledAstate.
Consider the following:
boolean cold, hot;
cold = true;
// Later in the program...
hot = !cold;
If we start out with an environment where the room is cold, so the cold sensor is true. Therefore, "not cold" (i.e., ! cold) can be interpreted as hot. You will often see the NOT operator used to toggle a variable, perhaps between OFF and ON:
sensor = ! sensor; // Reverses its state from ON to OFF, or from OFF to ON.
Does it make a difference if there is a space between the ! and the variable? Compiling issues?
sensor = ! sensor
vs
sensor = !sensor
Vampyrewolf:
Does it make a difference if there is a space between the ! and the variable? Compiling issues?sensor = ! sensor
vs
sensor = !sensor
You can always write a small sketch to show what happens