Hello, I'm working on a school project involving an arduino due , a pixy camera and a scorbot robotic arm. I want the arduino to transmit the co-ordinates of objects seen by pixy to the scorbot so that it can then reach out and grab said object ( this is my first time using arduino). The program i'm using came for the pixy wiki forums , here it is
// Author: Scott Robinson
// charmedlabs.com
//
// Continuously prints blob data
// using the Pixy library.
#include <SPI.h>
#include <Pixy.h>
Pixy pixy;
void setup()
{
analogWriteResolution(12);
pinMode(22, OUTPUT);
Serial.begin(9600);
Serial.print("Starting...\n");
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[16];
int Xpositie;
int Ypositie;
blocks = pixy.getBlocks();
if (blocks)
{
i++;
if (i%50==0)
{
sprintf(buf, "Detected %d:\n", blocks);
Serial.print(buf);
for (j=0; j<blocks; j++)
{
sprintf(buf, " block %d: ", j);
Serial.print(buf);
pixy.blocks[j].print();
//From here I assume Pixy is trained to see only objects of one specific colour and that there is not more than one object in the image.
// If this object is detected pin 22 is high and the position is outputted as 2 analogue voltages on DAC0 and DAC1 of an Arduino Due
if (blocks[j].signature==0)
{
digitalWrite(22, HIGH);
Xpositie=int(float(pixy.blocks[j].x/3194095)); //Here the X-position of 0 to 319 is transformed to 0 to 4095 for the analogue output DAC0 of the arduino due.
Ypositie=int(float(pixy.blocks[j].y/1994095)); //Here the Y-position of 0 to 199 is transformed to 0 to 4095 for the analogue output DAC1 of the arduino due.
analogWrite(DAC0,Xpositie);//The transformed X-position is here outputted to DAC0
analogWrite(DAC1,Ypositie);//The transformed Y-position is here outputted to DAC1
delay(50);
}
// If there is no object detected pin 22 is low and the values of the 2 analogue voltages on DAC0 and DAC1 is not important
else
{
digitalWrite(22, LOW);
delay(50);
}
}
}
}
}
but it isn't doing what its supposed to, I'll show the pixy an object of the correct colour signature but the if statement: if (blocks[j].signature==0), doesn't go into effect .The x,y,z coordinate of objects that the pixy recognises show up on the serial monitor though. I tested this with LEDs and and saw that when an object was it wasn't preforming the if statement. Is there a way to extract that information from the serial monitor and then output it through the DAC ports.