I don’t understand yet -
1.) what is the frame thing for?
of course I want to get the whole amount of data as quick and as complete as possible!
I’m using a TFT screen additonally to display the blocks on it - which is admittedly rather slow (see code below!)
So what to do about this
if (i%50==0)
?
keep it or drop it?
2.) what to do in order to get the data of all the color codes if I trained 7 different ones?
what is the source code like for Arduino to get them?
// pixy-cam LCDTFT monitoring program
// pixyTFTSPI
// Pixy Cam connected by SPI
// version 0008
#include
#include
#include
// UTFT myGLCD(Model,SDA,SCL,CS,RST,RS)
// adjust the model parameter to suit the display module!
UTFT myGLCD(QD220A,43,42,41,0,40);
extern uint8_t SmallFont[];
uint8_t ScrRatio;
Pixy pixy;
void setup()
{
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
pixy.init();
//pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
//pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
// Pixy_maxSize/(GLCD_maxSize-frame)
ScrRatio=max(320/(myGLCD.getDisplayXSize()-20), 200/(myGLCD.getDisplayYSize()-20) )+1;
myGLCD.clrScr();
Serial.begin(19200);
}
uint16_t sigcolor( uint8_t signature) { // <<<<<<<<<<<<<<< customize !! <<<<<<<<<<
uint16_t color;
if(signature==1) color=VGA_RED; // light red
else
if(signature==2) color=VGA_AQUA; // light blue
else
if(signature==3) color=VGA_YELLOW; // just yellow ;)
else
if(signature==4) color=VGA_LIME; // light green
else
if(signature==5) color=VGA_FUCHSIA; // light pink
else
if(signature==6) color=VGA_BLUE; // dark blue
else
if(signature==7) color=VGA_PURPLE; // dark pink
else
color=VGA_WHITE;
return color;
}
char sbuf[240];
#define maxblocks 64
uint8_t blockS[maxblocks];
uint8_t blockX[maxblocks];
uint8_t blockY[maxblocks];
uint8_t blockW[maxblocks];
uint8_t blockH[maxblocks];
void loop()
{
static int i = 0;
int j;
uint16_t nblocks;
uint8_t x1,y1,x2,y2;
nblocks = pixy.getBlocks();
if (nblocks)
{
i++;
if (i % 10==0)
{
myGLCD.clrScr();
sprintf(sbuf, "Detected %d:\n", nblocks);
Serial.print(sbuf);
for (j=0; j<min(nblocks,maxblocks); j++)
{
sprintf(sbuf, " block %d: ", j);
Serial.print(sbuf);
pixy.blocks[j].print();
blockS[j]= pixy.blocks[j].signature;
blockX[j]= pixy.blocks[j].x;
blockY[j]= pixy.blocks[j].y;
blockW[j]= pixy.blocks[j].width;
blockH[j]= pixy.blocks[j].height;
myGLCD.setColor(sigcolor(blockS[j])); myGLCD.setBackColor(VGA_BLACK);
x1=blockX[j]-blockW[j]/2;
x2=blockX[j]+blockW[j]/2;
y1=blockY[j]-blockH[j]/2;
y2=blockY[j]+blockH[j]/2;
myGLCD.drawRect(x1/ScrRatio, y1/ScrRatio, x2/ScrRatio, y2/ScrRatio );
sprintf(sbuf, "%d", blockS[j]);
myGLCD.print(sbuf, (x1+10)/ScrRatio,(y1+10)/ScrRatio);
}
}
}
}
//
// begin Pixy cmucam license header
//
// This file is part of Pixy CMUcam5 or "Pixy" for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// [email protected]. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//
/*
06.04.2014 v0.1.3 John Leimon
+ Now using pixy.init() to initialize Pixy in setup().
The API consists of one call: getBlocks(), which returns the number of objects Pixy has detected.
You can then look in the pixy.blocks[] array for information about each detected object
(one array member for each detected object.)
Each array member (i) contains the following fields:
pixy.blocks[i].signature The signature number of the detected object (1-7)
pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
pixy.blocks[i].width The width of the detected object (1 to 320)
pixy.blocks[i].height The height of the detected object (1 to 200)
pixy.blocks[i].print() A member function that prints the detected object information to the serial port
*/
/* UTFT API (c) Henning Karlsen
// VGA color palette
#define VGA_BLACK 0x0000
#define VGA_WHITE 0xFFFF
#define VGA_RED 0xF800
#define VGA_GREEN 0x0400
#define VGA_BLUE 0x001F
#define VGA_SILVER 0xC618
#define VGA_GRAY 0x8410
#define VGA_MAROON 0x8000
#define VGA_YELLOW 0xFFE0
#define VGA_OLIVE 0x8400
#define VGA_LIME 0x07E0
#define VGA_AQUA 0x07FF
#define VGA_TEAL 0x0410
#define VGA_NAVY 0x0010
#define VGA_FUCHSIA 0xF81F
#define VGA_PURPLE 0x8010
#define VGA_TRANSPARENT 0xFFFFFFFF
UTFT();
UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0);
void InitLCD(byte orientation=LANDSCAPE);
void clrScr();
void drawPixel(int x, int y);
void drawLine(int x1, int y1, int x2, int y2);
void fillScr(byte r, byte g, byte b);
void fillScr(word color);
void drawRect(int x1, int y1, int x2, int y2);
void drawRoundRect(int x1, int y1, int x2, int y2);
void fillRect(int x1, int y1, int x2, int y2);
void fillRoundRect(int x1, int y1, int x2, int y2);
void drawCircle(int x, int y, int radius);
void fillCircle(int x, int y, int radius);
void setColor(byte r, byte g, byte b);
void setColor(word color);
word getColor();
void setBackColor(byte r, byte g, byte b);
void setBackColor(uint32_t color);
word getBackColor();
void print(char *st, int x, int y, int deg=0);
void print(String st, int x, int y, int deg=0);
void printNumI(long num, int x, int y, int length=0, char filler=' ');
void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
void setFont(uint8_t* font);
uint8_t* getFont();
uint8_t getFontXsize();
uint8_t getFontYsize();
void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
void lcdOff();
void lcdOn();
void setContrast(char c);
int getDisplayXSize();
int getDisplayYSize();
*/