Hello.
We’re building an object recognition car with pixy2 and aduino.
Signature 1 recognized the object and Signature 3 recognized the object.
Signature 1 implements recognizing and following objects.
Signature three implements recognizing and avoiding objects.
There’s a problem.
Signature 1 implements recognition and follow.
Signature three recognizes things and doesn’t evade them, it keeps on following them.
How do I change the code?
#include <Wire.h>
#include <Pixy2.h>
#include <SoftwareSerial.h>
#define mg2 7
#define mg1 8
#define md1 9
#define md2 10
#define ledPin 5
Pixy2 pixy;
SoftwareSerial mySerial(2, 3); //블루투스 핀
void setup() {
pinMode(md1, OUTPUT);
pinMode(md2, OUTPUT);
pinMode(mg1, OUTPUT);
pinMode(mg2, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(115200); //메인 시리얼 속도
Serial.print(“Starting…\n”);
mySerial.begin(9600); //블루투스 시리얼 속도
pixy.init();
}
void loop() {
static int i = 0;
int32_t left, right;
int j;
uint16_t blocks;
char buf[32];
char code;
pixy.ccc.getBlocks();
blocks = pixy.ccc.getBlocks();
if(mySerial.available()){
code=(mySerial.read());
if(code == ‘0’ or ‘1’){
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
}
}
if(code == ‘0’) //코드가 0이면 동작
{
if (blocks)
{
i++;
if (i%50==0)
{
sprintf(buf, “Detected %d:\n”, blocks);
Serial.print(buf);
for (j=0; j<blocks; j++)
{
sprintf(buf, " block %d: ", j);
Serial.print(buf);
pixy.ccc.blocks[j].print();
}
}
if((pixy.ccc.blocks[0].m_x>120)&&(pixy.ccc.blocks[0].m_x<190)) {go ();}
if((pixy.ccc.blocks[0].m_x<120) && (pixy.ccc.blocks[0].m_x>10)) {righting();}
if(pixy.ccc.blocks[0].m_x>190) {lefting();}
if((pixy.ccc.blocks[3].m_x>120)&&(pixy.ccc.blocks[3].m_x<190)) {avoidlefting();}
if((pixy.ccc.blocks[3].m_x<120) && (pixy.ccc.blocks[3].m_x>10)) {avoidlefting();}
if(pixy.ccc.blocks[3].m_x>190) {avoidrighting();}
}
else{stop();}}
else{stop();}}