<< return to Pixycam.com

I want to original pixy code convert to pixy2 code


i got original pixy code but i using pixy2. i try 2 week convert to pixy2 code and I looked at the examples in pixycam.com but i cant handle it. anyone help me ?

#include <Servo.h>
#include <Pixy.h>

Servo myservo; // create servo object to control a servo
Pixy pixy; // create pixy object for controlling the pixy camera

// function for testing the servo
void test_camera(){
myservo.write(90); // get the camera centered

void setup() {
//Serial.begin(9600); // initialize serial
myservo.attach(9); // attaches the servo on pin 9 to the servo object
test_camera(); // executing testing for the servo
pixy.init(); // initing the pixy camera

void loop() {
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
int32_t xpos;

// grabing the blocks
blocks = pixy.getBlocks();

// If there are detect blocks
if (blocks)

// we are using 50FPS 
if (i%50==0)
sprintf(buf, "Detected %d:\n", blocks);
for (j=0; j<blocks; j++)
	sprintf(buf, "  block %d: ", j);
	//Serial.println((((pixy.blocks[j].x)/2)+10)-60); //print out to what position will the servo go

	// this is used so the servo can't get stuck at minimum and maximum values
	if(((((pixy.blocks[j].x)/2)+10)-60) > 180 || ((((pixy.blocks[j].x)/2)+10)-60) < 0 ) 
  	myservo.write(90);  // if at min or max go to the middle

	// if there is no problem with min and max



It looks like an adaptation of the original hello_world example.

The new hello_world example is here (ccc_hello_world):

I don’t think much has changed, actually.



i found these code in https://www.deviceplus.com/how-tos/arduino-guide/an-intro-to-cmucam5-pixy-vision-camera-sensor/