marc le dep
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI TS_DISCO_F429ZI mbed
automatique.cpp@0:4910cdb3d377, 2018-03-29 (annotated)
- Committer:
- Alex_mln
- Date:
- Thu Mar 29 06:19:39 2018 +0000
- Revision:
- 0:4910cdb3d377
- Child:
- 1:59fe933886bd
marc le pd d'australie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alex_mln | 0:4910cdb3d377 | 1 | #include "automatique.h" |
Alex_mln | 0:4910cdb3d377 | 2 | #include "capteur.h" |
Alex_mln | 0:4910cdb3d377 | 3 | |
Alex_mln | 0:4910cdb3d377 | 4 | LCD_DISCO_F429ZI lcd3; |
Alex_mln | 0:4910cdb3d377 | 5 | TS_DISCO_F429ZI ts3; |
Alex_mln | 0:4910cdb3d377 | 6 | TS_StateTypeDef tsState3; |
Alex_mln | 0:4910cdb3d377 | 7 | uint16_t xa, ya; |
Alex_mln | 0:4910cdb3d377 | 8 | |
Alex_mln | 0:4910cdb3d377 | 9 | DigitalOut led1(PG_7); //lente gauche |
Alex_mln | 0:4910cdb3d377 | 10 | DigitalOut led2(PB_4); //rapide |
Alex_mln | 0:4910cdb3d377 | 11 | |
Alex_mln | 0:4910cdb3d377 | 12 | DigitalOut led3(PA_8); //lente droite |
Alex_mln | 0:4910cdb3d377 | 13 | DigitalOut led4(PA_14); //rapide |
Alex_mln | 0:4910cdb3d377 | 14 | |
Alex_mln | 0:4910cdb3d377 | 15 | DigitalOut led5(PC_12); //arrêt |
Alex_mln | 0:4910cdb3d377 | 16 | |
Alex_mln | 0:4910cdb3d377 | 17 | |
Alex_mln | 0:4910cdb3d377 | 18 | int vitesse; |
Alex_mln | 0:4910cdb3d377 | 19 | |
Alex_mln | 0:4910cdb3d377 | 20 | // Pour l'instant avec 1 capteur : ligne = avant ; blanc = arret |
Alex_mln | 0:4910cdb3d377 | 21 | |
Alex_mln | 0:4910cdb3d377 | 22 | void detectiona(){ |
Alex_mln | 0:4910cdb3d377 | 23 | xa = tsState3.X; |
Alex_mln | 0:4910cdb3d377 | 24 | ya = tsState3.Y; |
Alex_mln | 0:4910cdb3d377 | 25 | uint8_t text[7]; |
Alex_mln | 0:4910cdb3d377 | 26 | sprintf((char*)text, "%d; %d", xa, ya); |
Alex_mln | 0:4910cdb3d377 | 27 | lcd3.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); } |
Alex_mln | 0:4910cdb3d377 | 28 | |
Alex_mln | 0:4910cdb3d377 | 29 | void freqled(int indice){ |
Alex_mln | 0:4910cdb3d377 | 30 | if (indice==1){ |
Alex_mln | 0:4910cdb3d377 | 31 | led1=!led1; |
Alex_mln | 0:4910cdb3d377 | 32 | } |
Alex_mln | 0:4910cdb3d377 | 33 | else if (indice==2){ |
Alex_mln | 0:4910cdb3d377 | 34 | led2=!led2; |
Alex_mln | 0:4910cdb3d377 | 35 | } |
Alex_mln | 0:4910cdb3d377 | 36 | else if (indice==3){ |
Alex_mln | 0:4910cdb3d377 | 37 | led3=!led3; |
Alex_mln | 0:4910cdb3d377 | 38 | } |
Alex_mln | 0:4910cdb3d377 | 39 | else if (indice==4){ |
Alex_mln | 0:4910cdb3d377 | 40 | led4=!led4; |
Alex_mln | 0:4910cdb3d377 | 41 | } |
Alex_mln | 0:4910cdb3d377 | 42 | } |
Alex_mln | 0:4910cdb3d377 | 43 | |
Alex_mln | 0:4910cdb3d377 | 44 | |
Alex_mln | 0:4910cdb3d377 | 45 | |
Alex_mln | 0:4910cdb3d377 | 46 | void action(bool c1, bool c2, bool c3){ |
Alex_mln | 0:4910cdb3d377 | 47 | /* led5=1; |
Alex_mln | 0:4910cdb3d377 | 48 | led1=0; |
Alex_mln | 0:4910cdb3d377 | 49 | led2=0; |
Alex_mln | 0:4910cdb3d377 | 50 | led3=0; |
Alex_mln | 0:4910cdb3d377 | 51 | led4=0;*/ |
Alex_mln | 0:4910cdb3d377 | 52 | if(c1==false && c2==true && c3==false){ |
Alex_mln | 0:4910cdb3d377 | 53 | led5=0; |
Alex_mln | 0:4910cdb3d377 | 54 | //clignotement normal des deux LEDs lentes |
Alex_mln | 0:4910cdb3d377 | 55 | led1=1; |
Alex_mln | 0:4910cdb3d377 | 56 | led3=1; |
Alex_mln | 0:4910cdb3d377 | 57 | // freqled(1); |
Alex_mln | 0:4910cdb3d377 | 58 | // freqled(3); |
Alex_mln | 0:4910cdb3d377 | 59 | wait(1); |
Alex_mln | 0:4910cdb3d377 | 60 | led1=0; |
Alex_mln | 0:4910cdb3d377 | 61 | led3=0; |
Alex_mln | 0:4910cdb3d377 | 62 | // freqled(1); |
Alex_mln | 0:4910cdb3d377 | 63 | // freqled(3); |
Alex_mln | 0:4910cdb3d377 | 64 | wait(1);//(10/vitesse)-(vitesse/1000)); |
Alex_mln | 0:4910cdb3d377 | 65 | }// led1=0; |
Alex_mln | 0:4910cdb3d377 | 66 | // led3=0; |
Alex_mln | 0:4910cdb3d377 | 67 | else{ |
Alex_mln | 0:4910cdb3d377 | 68 | led1=1; |
Alex_mln | 0:4910cdb3d377 | 69 | led2=1; |
Alex_mln | 0:4910cdb3d377 | 70 | led3=1; |
Alex_mln | 0:4910cdb3d377 | 71 | led4=1; |
Alex_mln | 0:4910cdb3d377 | 72 | led5=1; }} |
Alex_mln | 0:4910cdb3d377 | 73 | |
Alex_mln | 0:4910cdb3d377 | 74 | |
Alex_mln | 0:4910cdb3d377 | 75 | |
Alex_mln | 0:4910cdb3d377 | 76 | |
Alex_mln | 0:4910cdb3d377 | 77 | |
Alex_mln | 0:4910cdb3d377 | 78 | |
Alex_mln | 0:4910cdb3d377 | 79 | |
Alex_mln | 0:4910cdb3d377 | 80 | |
Alex_mln | 0:4910cdb3d377 | 81 | |
Alex_mln | 0:4910cdb3d377 | 82 | |
Alex_mln | 0:4910cdb3d377 | 83 | int go_automatique(int vit){ |
Alex_mln | 0:4910cdb3d377 | 84 | vitesse=vit; |
Alex_mln | 0:4910cdb3d377 | 85 | uint8_t status3 = ts3.Init(lcd3.GetXSize(), lcd3.GetYSize()); |
Alex_mln | 0:4910cdb3d377 | 86 | ts3.GetState(&tsState3); |
Alex_mln | 0:4910cdb3d377 | 87 | detectiona(); |
Alex_mln | 0:4910cdb3d377 | 88 | |
Alex_mln | 0:4910cdb3d377 | 89 | |
Alex_mln | 0:4910cdb3d377 | 90 | |
Alex_mln | 0:4910cdb3d377 | 91 | |
Alex_mln | 0:4910cdb3d377 | 92 | while((xa>225 || xa<12) || (ya<78-20 || ya>288-20)){ |
Alex_mln | 0:4910cdb3d377 | 93 | bool capt1=false;//code(1); |
Alex_mln | 0:4910cdb3d377 | 94 | bool capt2=code(2); |
Alex_mln | 0:4910cdb3d377 | 95 | bool capt3=false;//code(3); |
Alex_mln | 0:4910cdb3d377 | 96 | |
Alex_mln | 0:4910cdb3d377 | 97 | action(capt1,capt2,capt3); |
Alex_mln | 0:4910cdb3d377 | 98 | |
Alex_mln | 0:4910cdb3d377 | 99 | int value=afficher(); |
Alex_mln | 0:4910cdb3d377 | 100 | showIntegerScreen((int)(value),1,0,RIGHT_MODE); |
Alex_mln | 0:4910cdb3d377 | 101 | showIntegerScreen(0,0,0,RIGHT_MODE); |
Alex_mln | 0:4910cdb3d377 | 102 | wait(0.2); |
Alex_mln | 0:4910cdb3d377 | 103 | |
Alex_mln | 0:4910cdb3d377 | 104 | |
Alex_mln | 0:4910cdb3d377 | 105 | |
Alex_mln | 0:4910cdb3d377 | 106 | |
Alex_mln | 0:4910cdb3d377 | 107 | |
Alex_mln | 0:4910cdb3d377 | 108 | |
Alex_mln | 0:4910cdb3d377 | 109 | |
Alex_mln | 0:4910cdb3d377 | 110 | |
Alex_mln | 0:4910cdb3d377 | 111 | ts3.GetState(&tsState3); |
Alex_mln | 0:4910cdb3d377 | 112 | detectiona(); |
Alex_mln | 0:4910cdb3d377 | 113 | |
Alex_mln | 0:4910cdb3d377 | 114 | } |
Alex_mln | 0:4910cdb3d377 | 115 | return(1);} |