Pixy Project

Surce

Explain Project

Code Arduino

#include <SPI.h>
#include <Pixy.h>

Pixy pixy;

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

void loop()
{
  uint16_t type;
  static int i = 0;
  int j;
  int16_t signature;
  int16_t angle;
  uint16_t blocks;           
  blocks = pixy.getBlocks(); 
  if (blocks)                
  {
    i++;         //<<<<< ----- Delay each 50 Loops everi 50 loop go in
    if (i % 50 == 0) //<<<<< ----- Delay each 50 Loops everi 50 loop go in
    {
      Serial.print("Detected :");
      Serial.print(blocks);
      Serial.print("\n");

      for (j = 0; j < blocks; j++)
      {

        Serial.print("type =");
        Serial.print(pixy.blocks[j].type);
        Serial.print("\t");

        Serial.print("Sign =");
        signature = (pixy.blocks[j].signature);
        Serial.print(signature,OCT);
        Serial.print("\t");
        
        Serial.print("Loc X =");
        Serial.print(pixy.blocks[j].x);
        Serial.print("\t");
        
        Serial.print("Loc Y =");
        Serial.print(pixy.blocks[j].y);
        Serial.print("\t");
        
        Serial.print("width =");
        Serial.print(pixy.blocks[j].width);
        Serial.print("\t");
        
        Serial.print("Height =");
        Serial.print(pixy.blocks[j].height);
        Serial.print("\t");
        
        Serial.print("angle =");
        angle = (pixy.blocks[j].angle);
        Serial.print(angle);
        Serial.print("\t");
        
        pixy.blocks[j].print(); //<<<----- This print all one Line
      }
      Serial.print("\n\n");
    }
  }
}


Set 2 or more signatures in PixyMon, use this code to read each one on the Arduino

#include <Pixy.h>
Pixy pixy;

void setup()
{
  Serial.begin(9600);
  pixy.init();
}
void loop()
{
  static int i = 0;
  int j;
  int16_t signature;
  uint16_t blocks;           
  blocks = pixy.getBlocks(); 
  if (blocks)                
  {
    i++;         //<<<<< ----- Delay each 50 Loops everi 50 loop go in
    if (i % 50 == 0) //<<<<< ----- Delay each 50 Loops everi 50 loop go in
    {
 
     for (j = 0; j < blocks; j++)
      {
        signature = (pixy.blocks[j].signature);
      
            if (signature == 1)
               { 
               Serial.print("signature 1  ");                
               Serial.print("  Vertical =  ");
               Serial.print(pixy.blocks[j].x);
               Serial.print("  Horizontal =  ");
               Serial.println(pixy.blocks[j].y);
               }              
            
            if (signature == 2)
               { 
               Serial.print("signature 2  ");                
               Serial.print("  Vertical =  ");
               Serial.print(pixy.blocks[j].x);
               Serial.print("  Horizontal =  ");
               Serial.println(pixy.blocks[j].y);
               }
            
       }
    }
  }  
}