I got it working!
I did not quite understand your suggestion Edge but I think I have implemented it correctly now.
void loop()
{
// grab blocks!
result = pixy.ccc.getBlocks(false);
if (result < 0) //no new postion data so move steppers based on prior location data
{
if (targetX < 150) //get x coordinate of block 0 and check its location from center
{
digitalWrite(dirPin, LOW );
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
if (targetX > 165)
{
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
if (targetY < 96) //get y coordinate of block 0 and check its location from center
{
digitalWrite(dirPiny, LOW);
digitalWrite(stepPiny, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPiny, LOW);
delayMicroseconds(Speed);
}
if (targetY > 111)
{
digitalWrite(dirPiny, HIGH);
digitalWrite(stepPiny, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPiny, LOW);
delayMicroseconds(Speed);
}
}
else //update location of target based on new data from Pixy
{
targetX = pixy.ccc.blocks[0].m_x;
targetY = pixy.ccc.blocks[0].m_y;
}
}
My best guess is that when I was checking locations with pixy.ccc.blocks[0].m_x that it was returning an error when no new location data existed. So saving location data to a variable and only updating it when new data arrives solves the problem. I think lol
Whatever the problem was it is working now as intended. Thank you all for the assistance!
Brad