Pixy 2 And arduino center coordinates on object

Hi I am trying to create a program that when it catches a object that is at the center of the picture that the arduino performs a task.

     if (pixy.ccc.blocks[0].m_x - 160 == true  )
  {
      digitalWrite(3, HIGH);  
 }
  

    else{
            digitalWrite(3, LOW);  

    }

There is not enough detail here for anyone to assist you.
I would, however, suggest reducing that code sample to one line

(pixy.ccc.blocks[0].m_x - 160 == true  ) ?  digitalWrite(3, HIGH) : digitalWrite(3, LOW) ;

or even:

digitalWrite( 3, (pixy.ccc.blocks[0].m_x - 160 == true  ) ? HIGH : LOW ) ; 

does the same thing.

Hi, @trireso
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0

I know it does the same thing,
BUT WHY?
It makes it very hard for us non C++ super experts to read and decipher and even harder for beginners.

Tom... :grinning: :+1: :coffee: :australia:

I was simply making some light conversation until the OP showed up with some information that could be used to help solve what ever problem there is. I agree that there are different approaches to the use of C++ short hand constructs but it may indeed even be that the OP is a experienced C++ user.

Actually, that construct could be even shorter with a slight loss of clarity. :grinning:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.