How would i make this into an if statement?
digitalWrite(lager_pins[!L 2 ? : L - 2], HIGH);
With the ! And ?.. i can’t understand it.
How would i make this into an if statement?
digitalWrite(lager_pins[!L 2 ? : L - 2], HIGH);
With the ! And ?.. i can’t understand it.
That looks like a ternary expression except that the syntax is wrong.
The ! is logical not.
Invalid syntax:
error: expected ']' before numeric constant
digitalWrite(lager_pins[!L 2 ? : L - 2], HIGH);
^
Perhaps you meant:
digitalWrite(lager_pins[!L ? 2 : L - 2], HIGH);
That would be equivalent to:
if (!L)
digitalWrite(lager_pins[2], HIGH);
else
digitalWrite(lager_pins[L - 2], HIGH);
Which in turn would be equivalent to:
if (L == 0)
digitalWrite(lager_pins[2], HIGH);
else
digitalWrite(lager_pins[L - 2], HIGH);
johnwasser:
Invalid syntax:error: expected ']' before numeric constant
digitalWrite(lager_pins[!L 2 ? : L - 2], HIGH);
^
Perhaps you meant:digitalWrite(lager_pins[!L ? 2 : L - 2], HIGH);
That would be equivalent to:if (!L)
digitalWrite(lager_pins[2], HIGH);
else
digitalWrite(lager_pins[L - 2], HIGH);Which in turn would be equivalent to:if (L == 0)
digitalWrite(lager_pins[2], HIGH);
else
digitalWrite(lager_pins[L - 2], HIGH);
In which case, what happens when L == 1?
if (L == 0)
digitalWrite(lager_pins[2], HIGH);
else
digitalWrite(lager_pins[L - 2], HIGH);
In which case, what happens when L == 1?
Since 1 is not equal to 0 the else executes,
darrob:
In which case, what happens when L == 1?
Objection! Assumes facts not in evidence.
Let's hope that whatever code this is part of doesn't execute this line with L=1.
Sustained. Oops. == != =.
johnwasser:
Let's hope that whatever code this is part of doesn't execute this line with L=1.
Why not?
We don't know enough about the OP's code (hint) to form an opinion