marc le dep
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI TS_DISCO_F429ZI mbed
automatique.cpp@1:59fe933886bd, 2018-03-29 (annotated)
- Committer:
- Alex_mln
- Date:
- Thu Mar 29 07:14:46 2018 +0000
- Revision:
- 1:59fe933886bd
- Parent:
- 0:4910cdb3d377
sghkjlm
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 | 1:59fe933886bd | 3 | #include "fonctions.h" |
Alex_mln | 0:4910cdb3d377 | 4 | |
Alex_mln | 0:4910cdb3d377 | 5 | LCD_DISCO_F429ZI lcd3; |
Alex_mln | 0:4910cdb3d377 | 6 | TS_DISCO_F429ZI ts3; |
Alex_mln | 0:4910cdb3d377 | 7 | TS_StateTypeDef tsState3; |
Alex_mln | 0:4910cdb3d377 | 8 | uint16_t xa, ya; |
Alex_mln | 0:4910cdb3d377 | 9 | |
Alex_mln | 0:4910cdb3d377 | 10 | DigitalOut led1(PG_7); //lente gauche |
Alex_mln | 1:59fe933886bd | 11 | |
Alex_mln | 1:59fe933886bd | 12 | |
Alex_mln | 1:59fe933886bd | 13 | /* DigitalOut led2(PB_4); //rapide |
Alex_mln | 0:4910cdb3d377 | 14 | |
Alex_mln | 0:4910cdb3d377 | 15 | DigitalOut led3(PA_8); //lente droite |
Alex_mln | 0:4910cdb3d377 | 16 | DigitalOut led4(PA_14); //rapide |
Alex_mln | 0:4910cdb3d377 | 17 | |
Alex_mln | 0:4910cdb3d377 | 18 | DigitalOut led5(PC_12); //arrêt |
Alex_mln | 0:4910cdb3d377 | 19 | |
Alex_mln | 0:4910cdb3d377 | 20 | |
Alex_mln | 0:4910cdb3d377 | 21 | int vitesse; |
Alex_mln | 0:4910cdb3d377 | 22 | |
Alex_mln | 0:4910cdb3d377 | 23 | // Pour l'instant avec 1 capteur : ligne = avant ; blanc = arret |
Alex_mln | 0:4910cdb3d377 | 24 | |
Alex_mln | 0:4910cdb3d377 | 25 | void detectiona(){ |
Alex_mln | 0:4910cdb3d377 | 26 | xa = tsState3.X; |
Alex_mln | 0:4910cdb3d377 | 27 | ya = tsState3.Y; |
Alex_mln | 0:4910cdb3d377 | 28 | uint8_t text[7]; |
Alex_mln | 0:4910cdb3d377 | 29 | sprintf((char*)text, "%d; %d", xa, ya); |
Alex_mln | 0:4910cdb3d377 | 30 | lcd3.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); } |
Alex_mln | 0:4910cdb3d377 | 31 | |
Alex_mln | 0:4910cdb3d377 | 32 | void freqled(int indice){ |
Alex_mln | 0:4910cdb3d377 | 33 | if (indice==1){ |
Alex_mln | 0:4910cdb3d377 | 34 | led1=!led1; |
Alex_mln | 0:4910cdb3d377 | 35 | } |
Alex_mln | 0:4910cdb3d377 | 36 | else if (indice==2){ |
Alex_mln | 0:4910cdb3d377 | 37 | led2=!led2; |
Alex_mln | 0:4910cdb3d377 | 38 | } |
Alex_mln | 0:4910cdb3d377 | 39 | else if (indice==3){ |
Alex_mln | 0:4910cdb3d377 | 40 | led3=!led3; |
Alex_mln | 0:4910cdb3d377 | 41 | } |
Alex_mln | 0:4910cdb3d377 | 42 | else if (indice==4){ |
Alex_mln | 0:4910cdb3d377 | 43 | led4=!led4; |
Alex_mln | 0:4910cdb3d377 | 44 | } |
Alex_mln | 0:4910cdb3d377 | 45 | } |
Alex_mln | 0:4910cdb3d377 | 46 | |
Alex_mln | 0:4910cdb3d377 | 47 | |
Alex_mln | 0:4910cdb3d377 | 48 | |
Alex_mln | 0:4910cdb3d377 | 49 | void action(bool c1, bool c2, bool c3){ |
Alex_mln | 1:59fe933886bd | 50 | led5=1; |
Alex_mln | 0:4910cdb3d377 | 51 | led1=0; |
Alex_mln | 0:4910cdb3d377 | 52 | led2=0; |
Alex_mln | 0:4910cdb3d377 | 53 | led3=0; |
Alex_mln | 1:59fe933886bd | 54 | led4=0; |
Alex_mln | 0:4910cdb3d377 | 55 | if(c1==false && c2==true && c3==false){ |
Alex_mln | 0:4910cdb3d377 | 56 | led5=0; |
Alex_mln | 0:4910cdb3d377 | 57 | //clignotement normal des deux LEDs lentes |
Alex_mln | 0:4910cdb3d377 | 58 | led1=1; |
Alex_mln | 0:4910cdb3d377 | 59 | led3=1; |
Alex_mln | 0:4910cdb3d377 | 60 | // freqled(1); |
Alex_mln | 0:4910cdb3d377 | 61 | // freqled(3); |
Alex_mln | 0:4910cdb3d377 | 62 | wait(1); |
Alex_mln | 0:4910cdb3d377 | 63 | led1=0; |
Alex_mln | 0:4910cdb3d377 | 64 | led3=0; |
Alex_mln | 0:4910cdb3d377 | 65 | // freqled(1); |
Alex_mln | 0:4910cdb3d377 | 66 | // freqled(3); |
Alex_mln | 0:4910cdb3d377 | 67 | wait(1);//(10/vitesse)-(vitesse/1000)); |
Alex_mln | 0:4910cdb3d377 | 68 | }// led1=0; |
Alex_mln | 0:4910cdb3d377 | 69 | // led3=0; |
Alex_mln | 0:4910cdb3d377 | 70 | else{ |
Alex_mln | 0:4910cdb3d377 | 71 | led1=1; |
Alex_mln | 0:4910cdb3d377 | 72 | led2=1; |
Alex_mln | 0:4910cdb3d377 | 73 | led3=1; |
Alex_mln | 0:4910cdb3d377 | 74 | led4=1; |
Alex_mln | 0:4910cdb3d377 | 75 | led5=1; }} |
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 | |
Alex_mln | 0:4910cdb3d377 | 84 | |
Alex_mln | 0:4910cdb3d377 | 85 | |
Alex_mln | 0:4910cdb3d377 | 86 | int go_automatique(int vit){ |
Alex_mln | 0:4910cdb3d377 | 87 | vitesse=vit; |
Alex_mln | 0:4910cdb3d377 | 88 | uint8_t status3 = ts3.Init(lcd3.GetXSize(), lcd3.GetYSize()); |
Alex_mln | 0:4910cdb3d377 | 89 | ts3.GetState(&tsState3); |
Alex_mln | 0:4910cdb3d377 | 90 | detectiona(); |
Alex_mln | 0:4910cdb3d377 | 91 | |
Alex_mln | 0:4910cdb3d377 | 92 | |
Alex_mln | 0:4910cdb3d377 | 93 | |
Alex_mln | 0:4910cdb3d377 | 94 | |
Alex_mln | 0:4910cdb3d377 | 95 | while((xa>225 || xa<12) || (ya<78-20 || ya>288-20)){ |
Alex_mln | 0:4910cdb3d377 | 96 | bool capt1=false;//code(1); |
Alex_mln | 0:4910cdb3d377 | 97 | bool capt2=code(2); |
Alex_mln | 0:4910cdb3d377 | 98 | bool capt3=false;//code(3); |
Alex_mln | 0:4910cdb3d377 | 99 | |
Alex_mln | 0:4910cdb3d377 | 100 | action(capt1,capt2,capt3); |
Alex_mln | 0:4910cdb3d377 | 101 | |
Alex_mln | 0:4910cdb3d377 | 102 | int value=afficher(); |
Alex_mln | 0:4910cdb3d377 | 103 | showIntegerScreen((int)(value),1,0,RIGHT_MODE); |
Alex_mln | 0:4910cdb3d377 | 104 | showIntegerScreen(0,0,0,RIGHT_MODE); |
Alex_mln | 0:4910cdb3d377 | 105 | wait(0.2); |
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 | |
Alex_mln | 0:4910cdb3d377 | 112 | |
Alex_mln | 0:4910cdb3d377 | 113 | |
Alex_mln | 0:4910cdb3d377 | 114 | ts3.GetState(&tsState3); |
Alex_mln | 0:4910cdb3d377 | 115 | detectiona(); |
Alex_mln | 0:4910cdb3d377 | 116 | |
Alex_mln | 0:4910cdb3d377 | 117 | } |
Alex_mln | 1:59fe933886bd | 118 | return(1);}*/ |
Alex_mln | 1:59fe933886bd | 119 | |
Alex_mln | 1:59fe933886bd | 120 | |
Alex_mln | 1:59fe933886bd | 121 | int go_automatique(int vit){ |
Alex_mln | 1:59fe933886bd | 122 | for(int k=0;k<5;k++){ |
Alex_mln | 1:59fe933886bd | 123 | led1=!led1; |
Alex_mln | 1:59fe933886bd | 124 | wait(0.1);} |
Alex_mln | 1:59fe933886bd | 125 | while(1){ |
Alex_mln | 1:59fe933886bd | 126 | bool capt=code(2); |
Alex_mln | 1:59fe933886bd | 127 | |
Alex_mln | 1:59fe933886bd | 128 | if(capt==true){ |
Alex_mln | 1:59fe933886bd | 129 | led1=1;} |
Alex_mln | 1:59fe933886bd | 130 | else if(capt==false){ |
Alex_mln | 1:59fe933886bd | 131 | led1=0;} |
Alex_mln | 1:59fe933886bd | 132 | else{ |
Alex_mln | 1:59fe933886bd | 133 | erreur();} |
Alex_mln | 1:59fe933886bd | 134 | wait(0.1);} |
Alex_mln | 1:59fe933886bd | 135 | |
Alex_mln | 1:59fe933886bd | 136 | |
Alex_mln | 1:59fe933886bd | 137 | |
Alex_mln | 1:59fe933886bd | 138 | |
Alex_mln | 1:59fe933886bd | 139 | |
Alex_mln | 1:59fe933886bd | 140 | return(1); |
Alex_mln | 1:59fe933886bd | 141 | } |