![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Pixy (cmucam5) Library HelloWorld Program
Fork of TestPixy by
Diff: main.cpp
- Revision:
- 0:ff2018f6c7cd
- Child:
- 1:b3e8acec058f
diff -r 000000000000 -r ff2018f6c7cd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 31 17:37:26 2018 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "Pixy.h" + +Serial pc (PA_2, PA_3, 921600); +PIXY Pixy (PA_0, PA_1, 230400); + +DigitalOut led1 (PA_5); +DigitalOut led2 (PD_2); +DigitalOut disquette (PA_12); + +int main() +{ + int nbCC, nbNM, cr; + Byte msg, brightness = 50; + T_pixyCCBloc CCBuf; + T_pixyNMBloc NMBuf; + + pc.printf ("\r\nHelloWorld\r\n"); + led1 = 1; + led2 = 0; + disquette = 0; + + wait (5); + if (Pixy.checkPixy() == -1) { + pc.printf ("\rNo Pixy\n\r"); + while(1); + } else { + pc.printf ("\rLet's go\n\r"); + } + + do { + Pixy.setBrightness (brightness); + wait (0.2); + cr = Pixy.detectedObject (&nbNM, &nbCC); + pc.printf ("\r\nBrightness = %3d => nbCC = %2d - nbNM = %2d : cr = %2d ? ", brightness, nbCC, nbNM, cr); + msg = pc.getc(); + pc.printf("%c\r\n", msg); + if (msg=='a') brightness += 5; + if (msg=='q') brightness -= 5; + if (msg=='z') brightness += 1; + if (msg=='s') brightness -= 1; + } while (msg != 'X'); + + while (1) { + if (Pixy.checkNewImage()) { + cr = Pixy.detectedObject (&nbNM, &nbCC); + pc.printf ("\r\tnbCC = %2d - nbNM = %2d : cr = %2d\n", nbCC, nbNM, cr); + while (nbCC > 0) { + CCBuf = Pixy.getCCBloc (); + nbCC--; + pc.printf ("\rCC %5d : x=%5d, y=%5d - w=%5d, h=%5d, a=%5d\n", CCBuf.signature, CCBuf.x, CCBuf.y, CCBuf.width, CCBuf.height, (short)CCBuf.angle); + } + while (nbNM > 0) { + NMBuf = Pixy.getNMBloc (); + nbNM--; + pc.printf ("\rNM %4x : x=%5d, y=%5d - w=%5d, h=%5d\n", NMBuf.signature, NMBuf.x, NMBuf.y, NMBuf.width, NMBuf.height); + } + led1 = !led1; + led2 = !led2; + } + } +}