当Arduino通过pixy cam识别出某个物体时,我怎样才能让Arduino做某个动作

How can I make the Arduino do a certain action when it recognizes a certain object though the pixy cam

如果你能告诉我如何让 Arduino 显示检测到的对象的名称,这也会很有帮助。

你能告诉我我需要添加什么才能做到这一点吗:

#include <Pixy2.h>

// This is the main Pixy object 
Pixy2 pixy;

void setup()
{
  Serial.begin(115200);
  Serial.print("Starting...\n");
  
  pixy.init();
}

void loop()
{ 
  int i; 
  // grab blocks!
  pixy.ccc.getBlocks();
  
  // If there are detect blocks, print them!
  if (pixy.ccc.numBlocks)
  {
    Serial.print("Detected ");
    Serial.println(pixy.ccc.numBlocks);
    for (i=0; i<pixy.ccc.numBlocks; i++)
    {
      Serial.print("  block ");
      Serial.print(i);
      Serial.print(": ");
      pixy.ccc.blocks[i].print();
    }
  }  
}

我不确定你的问题是否正确,但据我记得 getBlocks() returns 你识别的对象的数量。鉴于已经检测到已知物体的情况,这个数字应该是正数。 由于您已经打印了这些块,是什么阻止您从此循环调用新功能?

关于如何显示名称的第二个问题我不太确定,你在找什么。您可以获取块的“签名”并将其用作名称,当然您可以将自己的名称与某些签名匹配。如果你想像所有其他值一样打印它们,你也可以使用 Serial.print() 。如果你想以不同的方式打印它们,例如液晶显示器,那么我们首先需要知道你的意图。

也许查看本教程以更好地掌握界面:https://www.open-electronics.org/pixy-camera-detect-the-colour-of-the-objects-and-track-their-position/