Need help understanding a line in someone elses sketch

Can someone explain what this line will return. It is located in the first if statement located in the first loop.

objectPresent = (powerCount < powerCountThreshold);

// Project 13 - Anti-gravity
// 15 Dangerous Projects for the Evil Genius

#define coilPin 11
#define irPin 13
#define sensorPin 0

int A = 2;
// Adjust B to improve stability 
int B = 60;
int C = 20;
int D = 1000;

int maxPower = 255; 
long powerCountThreshold = 300000;
int objectPresent = 0;
int monitoring = false;

void setup()
{
  pinMode(coilPin, OUTPUT);
  pinMode(irPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
  Serial.println("Ready");
  Serial.println("m - toggle monitoring");
  Serial.println("B - increase B");
  Serial.println("b - decrease B");
}

void loop()
{
  static int count = 0;
  static int oldPosition = 0;
  static int ambient = 0;
  static long powerCount = 0;
  count ++;
  
  if (count == 1000)
  {
    ambient = readAmbient();
    count = 0;
    objectPresent = (powerCount < powerCountThreshold);
    powerCount = 0;
  }
  int raw = 1024 - analogRead(sensorPin);
  // position from top (0) of sensor region to the bottom (650)
  int position = raw - ambient; 
  // positive value means going downwards, negative going upwards
  int velocity = position - oldPosition; 
  int power = position / A + velocity * B + C;

  powerCount += power;
  oldPosition = position;
  
  // clip
  if (power > maxPower) power = maxPower;
  if (power < 0) power = 0;

  checkSerial();
  
  if (monitoring)
  {
    Serial.print(position);  Serial.print(","); 
    Serial.println(velocity); 
  }
  
  analogWrite(coilPin, power * objectPresent);
  delayMicroseconds(D);
}

int readAmbient()   //todo try speding up delay in micros
{
  digitalWrite(irPin, LOW);
   // allow time for LED and phototransistor to settle
  delayMicroseconds(100);
  int ambient = 1024 - analogRead(sensorPin);
  digitalWrite(irPin, HIGH);
  return ambient;
}

void checkSerial()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch == 'm')
    {
      monitoring = ! monitoring;
    }
    if (ch == 'B') 
    {
      B += 5;
      Serial.println(B);
    }
    if (ch == 'b')
    {
      B -= 5;
      Serial.println(B);
    }
  }
}

Thanks

If powerCount is less than powerCountThreshold then the part in the parenthesis will be true so objectPresent gets set to true.

Otherwise it will be set to false in the same way.

That's a little awkward because objectPresent is defined as an int and (powerCount < powerCountThreshold) equals to either true or false. I guess it works because true can equal to 1 and false to 0 in the end. Then it's used in an equation power * objectPresent and for that you need a number int anyways.

Edit: In other environments, like Windows COM services, that wouldn't be a safe assumption at all...

Ok, thats what I thought but I wasn't sure. The only other place objectPresent is used is in the analogWrite statement.

One more quick question,

Right after the first if statement, "int position" is declared. Why is it declared in that part of the code and not with the rest of the declarations? Also, why is it highlighted?

Thanks again

Why is it declared in that part of the code and not with the rest of the declarations?

Because it is local to that function. The real question is why there are so many global variables when most of them should be local or passed as arguments.

Also, why is it highlighted?

It's not, on the forum. You need to explain what this means.

PaulS:

Also, why is it highlighted?

It's not, on the forum. You need to explain what this means.

When loaded int the Arduino IDE, "int position" is highlighted orange like a Serial.print would be highlighted.

Bill2k:

PaulS:

Also, why is it highlighted?

It's not, on the forum. You need to explain what this means.

When loaded int the Arduino IDE, "int position" is highlighted orange like a Serial.print would be highlighted.

You have a library installed that has declared "position" to be a keyword, and thus, "highlights" it.

Hrmm, I wonder which library that is. I didn't import any libraries into this sketch. Is it one of the IDE's basic libraries?

Bill2k:
Hrmm, I wonder which library that is. I didn't import any libraries into this sketch. Is it one of the IDE's basic libraries?

Doesn't matter if it was imported into the sketch or not, the library just has to be installed. It's purely cosmetic, though, it doesn't affect functionality.

Great to know. Thanks for the clarification.