Hi I am trying to send x and y pixel data from Pixy2 camera to matlab using arduino+bluetooth. But have trouble getting it to work.
This code works other way - where I send angle information from Matlab to servo motor through Bluetooth and arduino.
Any suggestions are most welcome.
#include <Pixy2.h>
#include <Servo.h>
//String readString; //String captured from serial port
Servo myservo; // create servo object to control a servo
int pos = 80; //position value to write to servo
// This is the main Pixy object
Pixy2 pixy;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
pixy.init();
}
void loop()
{
int i;
String strx;
String stry;
//int xcent =0;
// grab blocks!
pixy.ccc.getBlocks();
// If there are detect blocks, print them!
if (pixy.ccc.numBlocks)
{
//Serial.print("Detected ");
Serial.print(pixy.ccc.numBlocks);
Serial.print(":");
for (i=0; i<pixy.ccc.numBlocks; i++)
{
strx = String(pixy.ccc.blocks*.m_x);*
stry = String(pixy.ccc.blocks*.m_y);*
* Serial.print(strx);*
* Serial.print (",");*
* Serial.print(stry);*
* Serial.print ("&");*
* }*
* //Serial.println("$");*
* } *
* if (Serial.available() >0) {*
* pos = Serial.parseInt(); //convert readString into a number*
* if(pos >0){*
* myservo.write(pos);*
* }*
* delay(2);*
* }*
}