this coding detect 1 colour only.. i have try modify to 2 signiture but fail.. i need your opinion on how to detect 2 colour at once.. i give u example of coding.
- CODE: SELECT_ALL_CODE
#include <SPI.h>
#include <Pixy.h>
Pixy pixy;
int signature = 0;
int x = 0;
int y = 0;
unsigned int width = 0;
unsigned int height = 0;
unsigned int area = 0;
unsigned int newarea = 0;
int Xmin = 70;
int Xmax = 200;
int maxArea = 0;
int minArea = 0;
int motor1 = 4;
int enable1 = 5;
int motor2 = 7;
int enable2 = 6;
int Speed = 70;
static int i = 0;
void setup()
{
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(enable1, OUTPUT);
pinMode(enable2, OUTPUT);
Serial.begin(9600);
Stop();
pixy.init();
}
void loop()
{
while(millis()<5000)
{
scan();
area = width * height;
maxArea = area + 1000;
minArea = area - 1000;
}
scan();
if(signature == 2)
{
newarea = width * height;
if (x < Xmin)
{
left();
}
else if (x > Xmax)
{
right();
}
else if(newarea < minArea)
{
forward();
}
else if(newarea > maxArea)
{
backward();
}
//else stop
else
{
Stop();
}
}
else
{
Stop();
}
}
void backward()//backward
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
analogWrite(enable1, Speed);
analogWrite(enable2, Speed);
}
void forward()//forward
{
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
analogWrite(enable1, Speed);
analogWrite(enable2, Speed);
}
void right()//turn right
{
digitalWrite(motor1, HIGH);
digitalWrite(motor2, LOW);
analogWrite(enable1, Speed);
analogWrite(enable2, Speed);
}
void left()//turn left
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);
analogWrite(enable1, Speed);
analogWrite(enable2, Speed);
}
void Stop()//stop
{
digitalWrite(enable1, LOW);
digitalWrite(enable2, LOW);
}
void scan()
{
uint16_t blocks;
blocks = pixy.getBlocks();
signature = pixy.blocks[i].signature;
x = pixy.blocks[i].x;
y = pixy.blocks[i].y;
width = pixy.blocks[i].width;
height = pixy.blocks[i].height;
}