<< return to Pixycam.com

"pixyCheck" Doesn't Working

Hello, I am working with an Arduino and I found on the Internet a code used to check body coordinates and contained the command “pixyCheck” but an Arduino did not recognize it. What should I do?

#include <SPI.h>
#include <Pixy2.h>
Pixy2 pixy;
////////////////////////////////////////////////

//ENA IN1 IN2 IN3 IN4 ENB
int myPins[6] = {5, 6, 7, 8, 9, 10};
float deadzone = 0.15;
int baseSpeed = 130;

////////////////////////////////////////////////

int cont = 0;
int signature, x, y, width, height;
float cx, cy, area;

void setup()
{
Serial.begin(9600);
Serial.print(“Starting…\n”);
pixy.init();
for (int i = 0; i < 6; i++)
{
pinMode(myPins[i], OUTPUT);
}
}

void loop()
{
float turn = pixyCheck();
if(turn > -deadZone && turn <deadZone)
{
{
turn =0;
}

if (turn < 0)
{
moveRobot(-80, 170);
}
else if (turn > 0)
{
moveRobot(70, 70);
}
delay(i);
}

float pixyCheck()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
// grab blocks!
blocks = pixy.getBlocks();

//If there are detedt blocks, print them!
if (blocks)
{
signature = pixy.blocks[0].signatre;
height = pixy.blocks[0].height;
x = pixy.blocks[0].x;
y = pixy.blocks[0].y;
cx = (x + (width / 2));
cy = (y + (height / 2));
cx = mapfloat(cx, 0, 320, -1, 1);
cy = mapfloat(cy, 0, 200, 1, -1);
area = width * height;

// Serial.print(“sig: “);
// Serial.print(signature);
// Serial.print(” x:”);
// Serial.print(x);
// Serial.print(" y:");
// Serial.print(" width: “);
// Serial.print(width);
// Serial.print(” height: “);
// Serial.print(height);
// Serial.print(” cx: “);
// Serial.print(cx);
// Serial.print(” cy: ");
// Serial.print(cy);

}
else
{
cont *= 1;
if (cont == 100)
{
cont =0;
cx = 0;
}
}
return cx;
}

float mapfloat(long x, long in_min, long in_max, long out_min, long out_max)
{
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) +out_min;
}

void moveRobot(int leftSpeed, int rightSpeed)
}

Hello,
Is it a compilation issue? Perhaps you need to declare pixyCheck before you try to call it.

Edward

Hello Edward, thanks for the answer. I do not understand what you mean by pixyCheck declaring before you try to call it.

Hello,
It’s a C programming issue. If it sees a function it hasn’t seen before it will generate an error. You need to declare before using. You might google “C function declaration” for some help or ask a friend who’s familiar with C for assistance.

Edward

Sorry for the late answer, it worked! Thank you very much!