<< return to Pixycam.com

pixy2 and arduino

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);  

            digitalWrite(3, LOW);  


You need to replace “true” in this code with 0. Otherwise you are trying to compare an integer value to a Boolean, which will give unexpected results at best.

Also, this would only trigger if the object was exactly in the center. A better way might be to have some if statements that encapsulate a range of values, like:

if ((pixy.ccc.blocks[0].m_x > 140) && (pixy.ccc.blocks[0].m_x < 180)) {
 // do something