<< return to Pixycam.com

Is there a way to stop "getBlocks"?

I am using the arduino library. All works well, but here is my application.

I want to use Pixy to inspect a part. I have a push button that is triggered while I inspect, and I DONT want to inspect while I am not pushing the button.

So I came up with:

do
{
pixy.ccc.getBlocks();

if (pixy.ccc.numBlocks )
{
Serial.print("Detected ");
Serial.println(pixy.ccc.numBlocks);
digitalWrite(K1_Pin, 0);
}
else
digitalWrite(K1_Pin, 1);

}

while (digitalRead (Trig_Pin)==0); // button pushed

I discovered that Pixi will send me blocks wheder the button is pushed or not.

Is there a command to “Stop Getting Blocks”?

Thanks
Mitch

Hi Mitch,

I can think of two ways to do what you’re asking - first is switching programs, like this:

pixy.changeProg("video");

This will stop running the color_connected_components program, which tracks colored objects. To start tracking again, just do:

pixy.changeProg("color_connected_components");

Your other option is, when your button isn’t pressed, just ignore the data that Pixy2 sends!

Hope this helps,
Jesse

Hi Mitch,
you are telling the arduino to ‘inspect’ (do {…}) and after the inspection you tell it do it again if button is pushed. If the button is not pushed it has already inspected the object this cycle. Then this cycle ends and the arduino start over, next cycle, and starts from the top.
A better solution is to check if the button is pushed, than inspect and continue to do so while the condition stays the same (while(button) {-- your statements --}).
Edwards suggestion is great if you have a non-time-critical program. But remember: the switching between the modes of Pixy does take some time!
Sydney

Thanks a lot,
The " pixy.changeProg("color_connected_components");" method works , but when I deactivate and re activate, I am getting erroneous coordinates and width and height.

No big deal, I did some IF , ELSE method and I get what I want
Thanks everyone.

Next issue:

From your library example I am getting nice data about my block, such as
sig: 1 x: 214 y: 181 width: 120 height: 52 index: 168 age: 255

I want to assign arduino variables for each (position, size) how do I do that?
How do I extract them from your line?

pixy.ccc.blocks[i].print();

Thanks

Hello,
Regarding the block values (width, height, etc.), refer to the API:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api

You can access the width (for example) by using the expression

pixy.ccc.blocks[i].m_width

Hope this helps!

Edward