Hello!
I have a problem and I need your help!
I’m doing a project where I use a Pixycam and three servo motors and an Arduino.
The project is to pick up an object, show it to the Pixycam, and then put it in the appropriate box depending on what colour the object has.
My problem is that when I have Pixycam write out the signature of the object (= the colour code) in the Serial monitor in Arduino, it writes out that an object was detected when it is there (like it should do), but then also the first loop AFTER I TAKE IT AWAY. The second loop it works just as it should do.
If i replace the object with another one it detects that one instead, but when I take that one away and the Pixycam is suppose to write out “No blocks detected” in the Serial Monitor it shows the same as the one before, but then it shows “No blocks detected”.
This is my code if anyone wants to help me ’
#include <Servo.h>
#include <SPI.h>
#include <Pixy.h>
int servoPin = 30;
int servoPin2 = 40;
int servoPin3 = 26;
Servo Servo1;
Servo Servo2;
Servo Servo3;
Pixy pixy;
void setup() {
Servo1.attach(servoPin);
Servo2.attach(servoPin2);
Servo3.attach(servoPin3);
Serial.begin(57600);
Serial.print(“Starting…\n”);
pixy.init();
Servo2.writeMicroseconds(700);
delay(500);
Servo1.writeMicroseconds(1300);
delay(500);
}
void loop() {
int colour = 0;
static int i = 0;
int j = 0;
uint16_t blocks = 0;
uint16_t blockq = 0;
char buf[32];
delay(2000);
Servo3.writeMicroseconds(700);
delay(1000);
int a = 0;
for (a=0; a<80; a++)
{
blocks = pixy.getBlocks();
if(blocks)
{
blockq = blocks;
}
delay(50);
}
if(blockq)
{
colour = pixy.blocks[j].signature;
sprintf(buf, "Block: ", j);
Serial.print(buf);
pixy.blocks[j].print();
Serial.print ("The colour is nr. ");
Serial.print (colour);
Serial.print ("\n\n");
}
else
{
Serial.print(“No blocks detected\n\n”);
}
delay (2000);
Servo1.writeMicroseconds(1100);
delay(1000);
}