Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- theolp
- Date:
- 2019-11-28
- Revision:
- 26:a56cc5d715e9
- Parent:
- 25:2a2fcb9e4775
- Child:
- 27:bee63ac9b70b
File content as of revision 26:a56cc5d715e9:
#include "pixy2.h" /* _DEBUG_ */ int sommeDeControle,sommeRecue; Serial pc(USBTX, USBRX, 9600); /* */ typedef enum {IDLE, SND, CHECKSUM_ERROR, TIMEOUT, OK} T_state; // FLAGS char FLAG_BP = 0; // Prototypes void appui_BP(void); int main(void) { PIXY2 maPixy(PC_12, PD_2); // PC_12 : UART5_TX --- PD_2 : UART5_RX T_pixy2ErrorCode rep; // Initialisations InterruptIn BP(USER_BUTTON); BP.rise(&appui_BP); Timer temps; temps.start(); T_state etat = IDLE; while(1) { switch (etat) { case IDLE : if (FLAG_BP) { pc.printf("Envoi...\n\r"); etat = SND; FLAG_BP = 0; temps.reset(); } break; case SND : rep = maPixy.pixy2_getMainFeature(1); if (rep == PIXY2_BAD_CHECKSUM) { etat = CHECKSUM_ERROR; } if (temps.read()>0.5f) { etat = TIMEOUT; } if (rep >= PIXY2_VECTOR) { etat = OK; } break; case CHECKSUM_ERROR : pc.printf("Erreur de CheckSum...\n\r"); pc.printf("CheckSum Recu : %d\n\r", sommeRecue); pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle); etat = IDLE; break; case TIMEOUT : pc.printf("Erreur Timeout\n\r"); etat = IDLE; break; case OK : pc.printf("Number of vectors : %d\n\r", maPixy.Pixy2_numVectors); for(int i=0; i<maPixy.Pixy2_numVectors; ++i) { pc.printf("Vector number : %d\n\r", maPixy.Pixy2_vectors[i].pixIndex); pc.printf("x0 : %d - y0 : %d\n\r", maPixy.Pixy2_vectors[i].pixX0, maPixy.Pixy2_vectors[i].pixY0); pc.printf("x1 : %d - y1 : %d\n\r", maPixy.Pixy2_vectors[i].pixX1, maPixy.Pixy2_vectors[i].pixY1); } etat = IDLE; break; } } } // FONCTIONS void appui_BP(void) { FLAG_BP = 1; }