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.
Dependencies: BSP_DISCO_F746NG
main.cpp
00001 #include "mbed.h" 00002 #include "stm32746g_discovery_lcd.h" 00003 #include "stm32746g_discovery_ts.h" 00004 #include "fleche_g.h" 00005 #include "fleche_d.h" 00006 #include "fleche_b.h" 00007 #include "fleche_h.h" 00008 #include "modf_code.h" 00009 #include "retour.h" 00010 #include "drawBitmap.h" 00011 00012 //On assigne les deux ports analogiques du joystick en sorti 00013 AnalogIn inX(A4); 00014 AnalogIn inY(A5); 00015 int main() 00016 { 00017 //Variable d'initialisation 00018 TS_StateTypeDef TS_State; 00019 uint16_t x, y; 00020 uint8_t text[30]; 00021 uint8_t status; 00022 uint8_t idx; 00023 uint8_t cleared = 0; 00024 uint8_t prev_nb_touches = 0; 00025 //Valeur des 2 axes du joystick 00026 float axeX; 00027 float axeY; 00028 00029 //Code a faire pour deverouillez l'electro-aimant 00030 char code_a = 2; //gauche 00031 char code_b = 4;//droite 00032 char code_c = 2;//gauche 00033 char code_d = 4;//droite 00034 00035 //Variable qui vont varié via la position du Joystick 00036 char essai_a = 0; 00037 char essai_b = 0; 00038 char essai_c = 0; 00039 char essai_d = 0; 00040 00041 //Variables qui vont servir à bloquer des parties du programme 00042 char bloque = 0; 00043 char bloque_bouton = 0; 00044 char reset_mdp = 0; 00045 char victoire = 0; 00046 00047 //Variable utilisé pour connaitre le nombre de valeur deja selectionner pour le score 00048 char nombre = 0; 00049 //Permet de positionner les images de fleche sur l'ecran 00050 int col = 60; 00051 00052 //Variable permettant de donner un resultat a chaque variable d'essais 00053 char val = 0; 00054 00055 00056 //Variable utilisé pour le retour en arriere 00057 char val_a =0; 00058 char val_b =0; 00059 char val_c =0; 00060 char val_d =0; 00061 char i; 00062 00063 BSP_LCD_Init(); 00064 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); 00065 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); 00066 BSP_LCD_Clear(LCD_COLOR_WHITE); 00067 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO " , CENTER_MODE); 00068 HAL_Delay(1000); 00069 //Initialisation de l'ecran 00070 status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00071 if (status != TS_OK) { 00072 BSP_LCD_SetFont(&Font24); 00073 BSP_LCD_Clear(LCD_COLOR_GREEN); 00074 BSP_LCD_SetBackColor(LCD_COLOR_GREEN); 00075 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00076 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); 00077 } 00078 BSP_LCD_Clear(LCD_COLOR_WHITE); 00079 00080 00081 while(1){ 00082 BSP_TS_GetState(&TS_State); 00083 //Cette partie represente les boutons ainsi que l'utilisation du joystick, ils ne sont pas utilisable en cas de victoire 00084 if(victoire == 0){ 00085 BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 00086 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00087 BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)"Chercher le code ", CENTER_MODE); 00088 //Creation d'un bouton tactile 00089 drawBitmap(0,0,(const uint8_t *)modf_code); 00090 uint16_t x = TS_State.touchX[0]; 00091 uint16_t y = TS_State.touchY[0]; 00092 //Cette partie est pour modifier le mot de passe 00093 if (TS_State.touchDetected) { 00094 if(((x > 0) && (x < 100)) &&((y > 0) && (y<50))){ 00095 BSP_LCD_Clear(LCD_COLOR_WHITE); 00096 BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 00097 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00098 BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)"Modification mot de passe ", CENTER_MODE); 00099 reset_mdp = 1; 00100 code_a = 0; 00101 code_b = 0; 00102 code_c = 0; 00103 code_d = 0; 00104 col = 60; 00105 nombre = 0; 00106 00107 while(reset_mdp ==1){ 00108 //On recupere la valeur des 2 axes du joystick 00109 axeX = inX.read(); 00110 axeY = inY.read(); 00111 if( axeX == 1.0){ 00112 if (bloque == 0 ){ 00113 drawBitmap(col,100,(const uint8_t *)fleche_h); 00114 val = 1; 00115 bloque = 1; 00116 nombre = nombre + 1; 00117 col = col + 90; 00118 wait_us(200000); 00119 } 00120 } 00121 if( axeY <= 0.40){ 00122 if (bloque == 0 ){ 00123 drawBitmap(col,100,(const uint8_t *)fleche_g); 00124 val = 2; 00125 bloque = 1; 00126 nombre = nombre + 1; 00127 col = col + 90; 00128 wait_us(200000); 00129 } 00130 } 00131 if( axeX <= 0.40){ 00132 if (bloque == 0 ){ 00133 drawBitmap(col,100,(const uint8_t *)fleche_b); 00134 val = 3; 00135 bloque = 1; 00136 nombre = nombre + 1; 00137 col = col + 90; 00138 wait_us(200000); 00139 } 00140 } 00141 if( axeY == 1.0){ 00142 if (bloque == 0 ){ 00143 drawBitmap(col,100,(const uint8_t *)fleche_d); 00144 val = 4; 00145 bloque = 1; 00146 nombre = nombre + 1; 00147 col = col + 90; 00148 wait_us(200000); 00149 } 00150 } 00151 if (bloque == 1){ 00152 switch(nombre) { 00153 case 1: 00154 code_a = val; 00155 bloque = 0; 00156 break; 00157 case 2: 00158 code_b = val; 00159 bloque = 0; 00160 break; 00161 case 3: 00162 code_c = val; 00163 bloque = 0; 00164 break; 00165 case 4: 00166 code_d = val; 00167 nombre = 0; 00168 reset_mdp = 0; 00169 col = 60; 00170 bloque = 0; 00171 BSP_LCD_Clear(LCD_COLOR_WHITE); 00172 break; 00173 00174 } 00175 } 00176 } 00177 } 00178 } 00179 //Bouton pour supprimer le dernier resultat 00180 if(nombre > 0){ 00181 drawBitmap(380,0,(const uint8_t *)retour); 00182 uint16_t x = TS_State.touchX[0]; 00183 uint16_t y = TS_State.touchY[0]; 00184 if (TS_State.touchDetected) { 00185 if(((x > 380) && (x < 480)) &&((y > 0) && (y<100))){ 00186 col = 60; 00187 //On réaffiche les anciens résultats grace val_a, val_b 00188 for( i =0; i< nombre ; i++){ 00189 switch(i) { 00190 case 0: 00191 00192 val = 0; 00193 break; 00194 case 1: 00195 00196 essai_a = val_a; 00197 val = val_a; 00198 break; 00199 case 2: 00200 00201 essai_b = val_b; 00202 val = val_b; 00203 break; 00204 default : 00205 wait_us(5000); 00206 } 00207 switch(val){ 00208 case 0: 00209 BSP_LCD_Clear(LCD_COLOR_WHITE); 00210 break; 00211 case 1: 00212 drawBitmap(col,100,(const uint8_t *)fleche_h); 00213 col = col +90; 00214 break; 00215 case 2: 00216 drawBitmap(col,100,(const uint8_t *)fleche_g); 00217 col = col +90; 00218 break; 00219 case 3: 00220 drawBitmap(col,100,(const uint8_t *)fleche_b); 00221 col = col +90; 00222 break; 00223 case 4: 00224 drawBitmap(col,100,(const uint8_t *)fleche_d); 00225 col = col +90; 00226 break; 00227 default : 00228 wait_us(5000); 00229 } 00230 } 00231 nombre = nombre - 1; 00232 wait_us(200000); 00233 } 00234 } 00235 } 00236 } 00237 00238 wait_us(200000); 00239 axeX = inX.read(); 00240 axeY = inY.read(); 00241 //Utilisation du joystick pour tenter de trouver le bon mot de passe 00242 //Si l'on fait varier la position du joystick selon la position x ou y alors les valeurs vont varier d'environ 0.30 jusqu'à 1 00243 if(bloque_bouton == 0){ 00244 if( axeX == 1.0){ 00245 if (bloque == 0 ){ 00246 drawBitmap(col,100,(const uint8_t *)fleche_h); 00247 val = 1; 00248 bloque = 1; 00249 bloque_bouton = 1; 00250 nombre = nombre + 1; 00251 col = col + 90; 00252 } 00253 } 00254 if( axeY <= 0.40){ 00255 if (bloque == 0 ){ 00256 drawBitmap(col,100,(const uint8_t *)fleche_g); 00257 val = 2; 00258 bloque = 1; 00259 bloque_bouton = 1; 00260 nombre = nombre + 1; 00261 col = col + 90; 00262 } 00263 } 00264 if( axeX <= 0.40){ 00265 if (bloque == 0 ){ 00266 drawBitmap(col,100,(const uint8_t *)fleche_b); 00267 val = 3; 00268 bloque = 1; 00269 bloque_bouton = 1; 00270 nombre = nombre + 1; 00271 col = col + 90; 00272 } 00273 } 00274 if( axeY == 1.0){ 00275 if (bloque == 0 ){ 00276 drawBitmap(col,100,(const uint8_t *)fleche_d); 00277 val = 4; 00278 bloque = 1; 00279 bloque_bouton = 1; 00280 nombre = nombre + 1; 00281 col = col + 90; 00282 } 00283 } 00284 } 00285 if (bloque == 1){ 00286 switch(nombre) { 00287 case 0: 00288 BSP_LCD_Clear(LCD_COLOR_WHITE); 00289 break; 00290 case 1: 00291 00292 essai_a = val; 00293 val_a = val; 00294 bloque = 0; 00295 bloque_bouton = 0; 00296 break; 00297 case 2: 00298 00299 essai_b = val; 00300 val_b = val; 00301 bloque = 0; 00302 bloque_bouton = 0; 00303 break; 00304 case 3: 00305 00306 essai_c = val; 00307 val_c = val; 00308 bloque = 0; 00309 bloque_bouton = 0; 00310 break; 00311 00312 case 4: 00313 00314 essai_d = val; 00315 break; 00316 00317 } 00318 //Une fois positions mise on verifie si le code correspond au mot de passe 00319 if(essai_d != 0){ 00320 //Si le code est bon on affiche un ecran vert avec ecrit victoire et on fait varier la variable "victoire" pour desactiver l'utilisation des bouton ainsi que du joystick 00321 if(essai_a == code_a && essai_b == code_b && essai_c == code_c && essai_d == code_d){ 00322 if ( victoire == 0){ 00323 BSP_LCD_Clear(LCD_COLOR_GREEN); 00324 BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 00325 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00326 BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)"VICTOIRE", CENTER_MODE); 00327 } 00328 victoire = 1; 00329 } 00330 //Si il ne s'agit pas du mot de passe un ecran rouge apparait avec ecrit "FAUX" et le joueur est invité à reessayer 00331 else{ 00332 wait_us(200000); 00333 BSP_LCD_Clear(LCD_COLOR_RED); 00334 BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 00335 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00336 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"FAUX ", CENTER_MODE); 00337 wait_us(500000); 00338 essai_a = 0; 00339 essai_b = 0; 00340 essai_c = 0; 00341 essai_d = 0; 00342 nombre = 0; 00343 col = 60; 00344 BSP_LCD_Clear(LCD_COLOR_WHITE); 00345 bloque = 0; 00346 bloque_bouton = 0; 00347 } 00348 } 00349 } 00350 } 00351 }
Generated on Thu Jul 21 2022 19:21:22 by
1.7.2