Hello to the community.I want to make something like this https://www.youtube.com/watch?v=eVJrafabBkg with my pixy.It s an intresting project. I wrote a program and i tested it with a simple servo an i didnt make it work. Any ideas why it doesnt work ? here is my code. Thanks for the help.
#include
#include
#include
#include
double x;
double y;
int i = 0;
int j;
uint16_t blocks;
Servo myservo;
int pos = 0;
Pixy pixy;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
Serial.print("Starting...\n");
pixy.init();
}
void loop(){
blocks=pixy.getBlocks();
if (blocks){ i++;}
if(i%50==0){
x=pixy.blocks[0].x;
y=pixy.blocks[0].y;
pos=atan ((x-160)/y);
if(pos>0){
myservo.write(90+pos);
delay(15);
}
else{
myservo.write(90+pos);
}
}
else{
myservo.write(90);
}}