I’m doing an Arduino project using the Pixy camera in an unconventional way. My primary goal is to light up a red LED when I pick up a red signature, and a blue LED for a blue signature.
I already posted to the Arduino forums, however, I thought I’d also post here for good measure.
My primary problem is that my LEDs are only supposed to light up for a red or blue object. However, both stay flickering all the time.
What I seemed to be struggling with was getting the Pixy to accurately pick up a color signature. It was constantly printing red and blue signatures, even when it wasn’t looking at those type of objects. Currently, it perfectly tracks a red object, and doesn’t confuse it with other objects in the room. However, my two LEDs continue to flicker, even when signatures aren’t being picked up at all.
I can’t figure out if I have a hardware or software issue right now. First it seemed to be one, now the other. I’m really hoping this forum can point me in the right direction.
I will post a picture of my breadboard and code to be as clear as possible.
Lastly, I’m very new to this, so please be patient with me. I’m trying my best.
#include <Pixy2.h>
int led = 12;
int led2 = 11;
int sigRed = 1; // signature 1 is red objects
int sigBlue = 2; //signature 2 is blue
Pixy2 pixy; // instantiate a Pixy object
void setup() {
pinMode(led, OUTPUT);
Serial.begin(115200);
Serial.print(“Starting…\n”);
pixy.init(); // initialize the pixy
}
void loop() {
uint16_t blocks;
while (1)
{
blocks = pixy.ccc.getBlocks();
if ( blocks)
{
for (int i = 0; i< blocks;i++)
{
if (pixy.ccc.blocks[i].m_signature == sigRed)
{
digitalWrite(led, HIGH);
Serial.println("red");
} else{
digitalWrite (led, LOW);
Serial.println("NO HEROES HERE");
}
if (pixy.ccc.blocks[i].m_signature == sigBlue)
{
digitalWrite(led2, HIGH);
Serial.println("blue");
} else{
digitalWrite(led2, LOW);
Serial.println("NO SHAPESHIFTERS HERE");
}
}// end for
}// end if(blocks)
delay(50); // dont poll thge pixy too fast
}// end while
}