What does - digitalWrite(OutPin, correct ? HIGH : LOW); Mean/do ?

(deleted)

spycatcher2k:
Is that what this does?

Yes. It's equivalent to this:

if(correct)
  digitalWrite(OutPin,HIGH ); 
else
  digitalWrite(OutPin,LOW);

This "digitalWrite(OutPin, correct ? HIGH : LOW);" will do this

If digitalWrite(13,HIGH); is called it will set the pin HIGH. (It will send 5v trough pin 13).
If digitalWrite(13,LOW); is called it will set the pin LOW.(it will send 0v or GND trough pin 13).

For an if statement you will need to write this:

if (a==true) {
       digitalWrite(13,HIGH);
}
else{
       digitalWrite(13,LOW);
}

You need to set a as a boolean before the void setup.

The code will look like this:

boolean a = true;
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
  if (a==true) {
       digitalWrite(13,HIGH);
  }
  else{
       digitalWrite(13,LOW);
  }
}

OR

boolean a = true;
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
       digitalWrite(13,a);
}

The statement is using the ternary operator, which has the form:

expression1 = expression2 ? expression3 : expression4;

expression2 is usually a conditional operator and evalutates to True or False. If expression2 evaluates to logic True, expression3 is evaluated and its result assigned into expression1. If expression2 evaluates to logic False, expression4 is evaluated and its outcome is assigned into expression1.

1 Like

(deleted)