I’m trying to have my Pixy cam follow an IR blob
I can’t seem to get it to track anything, not sure where I’m going wrong
I’m using a motor to rotate a base that the Pixy sits on, powered by an Arduino
If anyone can let me know where I’m going wrong, please let me know
Code:
#include <Pixy.h>
#include <PixyI2C.h>
#include <PixySPI_SS.h>
#include <TPixy.h>
#include <SPI.h>
Pixy pixy;
int signature = 0;
int x = 0; //positon x axis
int y = 0; //position y axis
unsigned int width = 0; //object’s width
unsigned int height = 0; //object’s height
unsigned int area = 0;
unsigned int newarea = 0;
int Xmin = 70; //min x position
int Xmax = 200; //max x position
int maxArea = 0;
int minArea = 0;
int motor1 = 3; //motor1 on Pin 3
int enable1 = 4; //direction1 on Pin 4
int Speed = 10; //speed for motor
static int i = 0;
void setup() {
pinMode(motor1, OUTPUT);
pinMode(enable1, OUTPUT);
Serial.begin(9600);
pixy.init();
}
void loop() {
void right();//turn right
{
digitalWrite(motor1, HIGH);
}
void left();//turn left
{
digitalWrite(motor1, -HIGH);
}
void Stop();//stop
{
digitalWrite(enable1, LOW);
}
void scan(); {
uint16_t blocks;
blocks = pixy.getBlocks(); //receive data from pixy
signature = pixy.blocks[i].signature; //get object’s signature
x = pixy.blocks[i].x; //get x position
y = pixy.blocks[i].y; //get y position
width = pixy.blocks[i].width; //get width
height = pixy.blocks[i].height; //get height
}
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
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();
while(millis()<10000) {
scan();
area = width * height; //calculate the object area
maxArea = area + 1000;
minArea = area - 1000;}
}}}}