<< return to Pixycam.com

If else barcode detection


Hi, can someone explain me how work the if else barcode detection on the pixy as exemple : if (pixy.line.barcodes->m_code==0)
pixy.line.setNextTurn(90); // 90 degrees is a left turn
// code==5 is our right-turn sign
else if (pixy.line.barcodes->m_code==5)
pixy.line.setNextTurn(-90); // -90 is a right turn

I tried to do the same but turn on the led when the barcode 1 is detected and turn off the led when barcode 2 is detected


You need to be careful to make sure a barcode is detected before checking values as you’ve done.

   // Get latest data from Pixy, including main vector, new intersections and new barcodes.
   res = pixy.line.getMainFeatures();
   if (res&LINE_BARCODE)  // DO NOT FORGET THIS!!!!!!!!!!!!!!!
     if (pixy.line.barcodes->m_code==0)
     // ... etc

There is nothing to prevent you from reading pixy.line.barcodes->m_code, but if a code isn’t detected this value will contain invalid data.



Yes don’t worry i have set them on the top of my programme
but when i check on pixymon the pixymon detect every barcode


Have you a prgrm where the pixy detect a code bar, it turn on the arduino led on and when it detect a different barcode ( ex barcode 2 ) it turn off the arduino led