
LAST PUBLISH MATRIX PROJECT
Revision 2:552c5891b8c5, committed 2021-06-23
- Comitter:
- antoine_carpentier
- Date:
- Wed Jun 23 14:32:47 2021 +0000
- Parent:
- 1:7a7366246b30
- Commit message:
- LAST COMMIT
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 7a7366246b30 -r 552c5891b8c5 main.cpp --- a/main.cpp Tue Jun 22 11:55:19 2021 +0000 +++ b/main.cpp Wed Jun 23 14:32:47 2021 +0000 @@ -17,35 +17,44 @@ #include "italiebmp.h" /////////////////FIN INCLUSION DES LIBRAIRIES///////////////// -//////DEFINITION LARGEUR ET LONGUEURE DE LECRAN LED (L20-L23)////// + + +//////DEFINITION LARGEUR ET LONGUEURE DE LECRAN LED (L22-L25)////// #define WIDTH 64 #define HEIGHT 32 //////// FIN DEFINITION LARGEUR ET LONGUEURE DE LECRAN LED //////// + + //stb c'est le latch // LEDMatrix (a, b, c, d, oe_1, r1, r2, b1, b2, g1, g2, stb_1, clk_1); LEDMatrix matrix(D1,D10,D0,D11,D7, D5, D3, D4, D2, D8, D9, D12, D13); Ticker scanner; + // Display Buffer uint8_t displaybuf[2][WIDTH *HEIGHT] = { 0x00 }; -/////////DEFINITION DES PROTOTYPES (L36-L40)///////// + +/////////DEFINITION DES PROTOTYPES (L42-L46)///////// void page_accueil(void); void page_dessin(void); void page_drapeau(void); /////////FIN DE DEFINITION DES PROTOTYPES//////////// -/////////DEFINITION DES VARIABLES GLOBALES (L42-L46)///////// + +/////////DEFINITION DES VARIABLES GLOBALES (L49-L53)///////// int xb=0, yb=0; // La valeur de x et y correspondante a l'ecran LCD uint8_t text[30]; // SPRINTF int p=0;// Pour le multicolor /////////FIN DE DEFINITION DES VARIABLES GLOBALES //////////// -////////////////DEFINITION DES FONCTIONS DE DESSIN D'IMAGE (L48-L237)///////////////////// + + +////////////////DEFINITION DES FONCTIONS DE DESSIN D'IMAGE (L57-L246)///////////////////// //fleche void drawImage_fleche(int offsetX, int offsetY) { @@ -234,7 +243,10 @@ y++; } } -////////////////FIN DEFINITION DES FONCTIONS DE DESSIN D'IMAGE (L48-L237)///////////////////// +////////////////FIN DEFINITION DES FONCTIONS DE DESSIN D'IMAGE (L57-L246)///////////////////// + + + /// FONCTION DE SCAN DE L'ECRAN LED////// @@ -244,7 +256,10 @@ } ///FIN FONCTION DE SCAN DE L'ECRAN LED////// -///////////////////////// DEBUT DU MAIN (L247-LXXX)//////////////////////////////////////// + + + +///////////////////////// DEBUT DU MAIN (L262-L652)//////////////////////////////////////// int main() { TS_StateTypeDef TS_State; // Definition de l'objet qui servira pour la detection de clic sur la STM32 @@ -254,9 +269,8 @@ uint16_t x, y; uint8_t status; uint8_t idx; - uint8_t prev_nb_touches = 0; int i, c=1; - int page = 0; + int page = 0; // La variable page défini la page sur laquelle on se trouve; page = 0 = page d'accueil; page = 1 = page dessin; page = 2 = page drapeau int couleur=7;//1 rouge; 2 vert; 3 jaune; 4 bleu; 5 violet; 6 cyan; 7 blanc @@ -290,23 +304,29 @@ matrix.begin((uint8_t *)displaybuf, WIDTH, HEIGHT); // Sauv en mémoire la taille de la matrice LED - scanner.attach(scan, 0.0005); //Gère l'affiche sur la matrice LED + scanner.attach(scan, 0.0003); //Gère l'affiche sur la matrice LED //Un scan trop lent (>0.0009) provoque un effet de scintillement //Un scan trop rapide (<0.0001) provoque un effet d'allumage des LEDs qui sont sur la même ligne - matrix.clear(); - matrix.drawRect(0,0,21,64,4); - matrix.drawRect(21,0,43,64,7); + + matrix.clear(); //Fonction de nettoyage de la matrice, toutes les LEDs s'éteignent + + + // Drapeau de la France (sur la matrice) + matrix.drawRect(0,0,21,64,4); + matrix.drawRect(21,0,43,64,7);// Allumage d'une zone rectangulaire sur l'écran LED matrix.drawRect(43,0,64,64,1); + matrix.swap(); while (!matrix.synchro()); wait(1); matrix.clear(); + for (i=200; i>-400; i-=4) { matrix.clear(); - matrix.drawCharString(i,0,"MATRICE LED LP SESAM",c,fonts[0]); + matrix.drawCharString(i,0,"MATRICE LED LP SESAM",c,fonts[0]); //Affichage de texte sur la matrice matrix.drawCharString(i,15,"CARPENTIER ANTOINE",c,fonts[0]); matrix.swap(); wait(0.05); @@ -314,203 +334,84 @@ } matrix.clear(); - BSP_LCD_Clear(LCD_COLOR_WHITE); - + BSP_LCD_Clear(LCD_COLOR_WHITE); // Effacage de l'ecran LCD + + + ///////////// BOUCLE INFINI ////////////// while (1) { - BSP_TS_GetState(&TS_State); - if (TS_State.touchDetected) - { - // Clear lines corresponding to old touches coordinates - if (TS_State.touchDetected < prev_nb_touches) - { - for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) - { - BSP_LCD_ClearStringLine(idx); - } - } - prev_nb_touches = TS_State.touchDetected; - - - - for (idx = 0; idx < TS_State.touchDetected; idx++) - { - x = TS_State.touchX[idx]; - y = TS_State.touchY[idx]; - xb = x/7.5; - yb = y/7.5; - - } + + BSP_TS_GetState(&TS_State); // Recuperation de l'état du tactile + + if (TS_State.touchDetected) // Si l'écran est touché + { + x = TS_State.touchX[idx]; //Recuperation de la coordonné en x + y = TS_State.touchY[idx]; //Recuperation de la coordonné en y + xb = x/7.5; // xb fait correspondre la led aux pixels correspondant + yb = y/7.5; // yb fait correspondre la led aux pixels correspondant } + + + if (page == 0) + { + page_accueil(); // Par défault cette page est affiché + } + + //VERS PAGE DESSIN - if ((page == 0) && (x>= 10 && x<= 235) && (y>= 10 && y<= 235)) + if ((page == 0) && (x>= 10 && x<= 235) && (y>= 10 && y<= 235)) //Si nous sommes sur la page d'accueil et que nous cliquons dans la zone alors : { x=0; y=272; - BSP_LCD_Clear(LCD_COLOR_WHITE); + BSP_LCD_Clear(LCD_COLOR_WHITE); //On efface tout et on passe à la page suivante matrix.clear(); matrix.swap(); while (!matrix.synchro()); - page = 1; + page = 1; //Passage a la page dessin HAL_Delay(300); - } - - - // VERS DRAPEAU - if ((page==0)&&(x>=245 && x<=470)&&(y>= 10 && y<= 235)) - { - x=0; - y=0; - BSP_LCD_Clear(LCD_COLOR_WHITE); - matrix.clear(); - matrix.swap(); - while (!matrix.synchro()); - page = 2; - HAL_Delay(100); } - if (page == 0) - { - page_accueil(); - } - - else if (page == 2) + + // VERS DRAPEAU + if ((page==0)&&(x>=245 && x<=470)&&(y>= 10 && y<= 235)) //Si nous sommes sur la page d'accueil et que nous cliquons dans la zone alors : { - page_drapeau(); - - //HAUT GAUCHE - if ((x>= 8 && x<= 236) && (y>= 29 && y<= 103)) - { - x = 0; - y = 0; - //ALLEMAGNE - matrix.clear(); - matrix.drawRect(0,10,64,21,3); - matrix.drawRect(0,21,64,32,1); - matrix.swap(); - while (!matrix.synchro()); - - } - - // HAUT DROITE - else if ((x>= 244 && x<= 472) && (y>= 29 && y<= 103)) - { - x = 0; - y = 0; - // BELGE - matrix.clear(); - matrix.drawRect(21,0,43,64,3); - matrix.drawRect(43,0,64,64,1); - matrix.swap(); - while (!matrix.synchro()); - - - } - - // MILIEU GAUCHE - else if ((x>= 8 && x<= 236) && (y>= 110 && y<= 184)) - { - x = 0; - y = 0; - //BENIN - matrix.clear(); - matrix.drawRect(0,0,21,64,2); - matrix.drawRect(21,0,64,16,3); - matrix.drawRect(21,16,64,32,1); - matrix.swap(); - while (!matrix.synchro()); - - } + x=0; + y=0; + BSP_LCD_Clear(LCD_COLOR_WHITE); //On efface tout et on passe à la page suivante + matrix.clear(); + matrix.swap(); + while (!matrix.synchro()); + page = 2; //Passage a la page drapeau + HAL_Delay(100); + } - // MILIEU DROITE - else if ((x>= 244 && x<= 472) && (y>= 110 && y<= 184)) - { - x = 0; - y = 0; - //LGBT - matrix.clear();//1 rouge; 2 vert; 3 jaune; 4 bleu; 5 violet; 6 cyan; 7 blanc - matrix.drawRect(0,0,64,4,7); - matrix.drawRect(0,4,64,8,1); - matrix.drawRect(0,8,64,12,3); - matrix.drawRect(0,12,64,16,2); - matrix.drawRect(0,16,64,20,4); - matrix.drawRect(0,20,64,24,6); - matrix.drawRect(0,24,64,28,5); - matrix.drawRect(0,28,64,32,7); - matrix.swap(); - while (!matrix.synchro()); - - } - - // BAS GAUCHE - else if ((x>= 8 && x<= 236) && (y>= 192 && y<= 266)) - { - x = 0; - y = 0; - //FRANCE - matrix.clear(); - matrix.drawRect(0,0,21,64,4); - matrix.drawRect(21,0,43,64,7); - matrix.drawRect(43,0,64,64,1); - matrix.swap(); - while (!matrix.synchro()); - - } - - - // BAS DROITE - else if ((x>= 244 && x<= 472) && (y>= 192 && y<= 266)) - { - x = 0; - y = 0; - //ITALIE - matrix.clear(); - matrix.drawRect(0,0,21,64,2); - matrix.drawRect(21,0,43,64,7); - matrix.drawRect(43,0,64,64,1); - matrix.swap(); - while (!matrix.synchro()); - } - - if ((page==2)&&(x>= 458 && x<= 480) && (y>= 0 && y<= 22)) - { - BSP_LCD_Clear(LCD_COLOR_WHITE); - matrix.clear(); - matrix.swap(); - while (!matrix.synchro()); - x = 0; - y = 0; - page = 0; - - } - - } - - - else if(page == 1) + + + if(page == 1) //SI NOUS SOMMES SUR LA PAGE DESSIN: { - page_dessin(); + page_dessin(); //Dessin des rectangles - matrix.swap(); - while (!matrix.synchro()); + matrix.swap(); + while (!matrix.synchro()); if (y<241) { - if(couleur != 0) + if(couleur != 0) //SI LA GOMME N'EST PAS SELECTIONNé { - BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); - matrix.drawPoint(xb,yb,couleur); - } - else + BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); // Dessine sur l'ecran LCD + matrix.drawPoint(xb,yb,couleur); // Dessine sur la matrice LED aux coordonnées correspondantes à la où on touche sur la STM32 + // Taille du pointeur = 1x1 + } + + else //SI LA GOMME EST SELECTIONNé { - BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); - BSP_LCD_FillRect(x-7.5,y-7.5,22.5,22.5); + BSP_LCD_FillRect(x-7.5,y-7.5,22.5,22.5); //DESSINE DES CARRES BLANC SUR LECRAN LCD POUR EFFACER LA ZONE - matrix.drawPoint(xb,yb,couleur); + matrix.drawPoint(xb,yb,couleur); // Couleur = 0 = ETEINT matrix.drawPoint(xb+1,yb+1,couleur); matrix.drawPoint(xb-1,yb-1,couleur); matrix.drawPoint(xb+1,yb-1,couleur); @@ -518,92 +419,68 @@ matrix.drawPoint(xb-1,yb,couleur); matrix.drawPoint(xb,yb-1,couleur); matrix.drawPoint(xb+1,yb,couleur); - matrix.drawPoint(xb,yb+1,couleur); - } + matrix.drawPoint(xb,yb+1,couleur); // Taille du pointeur = 3x3 + } matrix.swap(); while (!matrix.synchro()); } - + + ////BARRE DES COMMANDE, CHOIX DES COULEURS DES LEDS, GOMME ... (L430-L536)///// if (x<=43 && x>=2 && y<=270 && y>=242 ) { p=0; - couleur = 1; - } + couleur = 1; //ROUGE + } if (x<=86 && x>=45 && y<=270 && y>=242 ) { p=0; - couleur = 2; - } + couleur = 2; //VERT + } if (x<=129 && x>=88 && y<=270 && y>=242 ) { p=0; - couleur = 4; - } + couleur = 4; //BLEU + } if (x<=172 && x>=131 && y<=270 && y>=242 ) { p=0; - couleur = 5; - } + couleur = 5; //VIOLET + } if (x<=215 && x>=174 && y<=270 && y>=242 ) { p=0; - couleur = 6; - } + couleur = 6; //CYAN + } if (x<=258 && x>=217 && y<=270 && y>=242 ) { p=0; - couleur = 3; - } + couleur = 3; //JAUNE + } if (x<=301 && x>=260 && y<=270 && y>=242 ) { p=0; - couleur = 7; - } - + couleur = 7; //BLANC + } + + + //CLIC MULTICOLOR if (x<=344 && x>=303 && y<=270 && y>=242 ) { - p=1; - } - - // GOMME - if (x<=396 && x>=355 && y<=267 && y>=254 ) - { - p=0; - couleur = 0; - } - - // EFFACE TOUT - if (x<=438 && x>=410 && y<=267 && y>=254 ) - { - x=0; - y=0; - BSP_LCD_Clear(LCD_COLOR_WHITE); - matrix.clear(); - } - - if ((x>= 458 && x<= 480) && (y>= 240 && y<= 270)) - { - BSP_LCD_Clear(LCD_COLOR_WHITE); - matrix.clear(); - matrix.swap(); - while (!matrix.synchro()); - x = 0; - y = 0; - page = 0; - } - + p=1; + } - //MULTICOLOR + //MULTICOLOR if (p==1) { + // DEFINITON DE ZONE ET DE COULEUR EN FONCTION if (x<68 && y<91)couleur=7; if (x>=68 && x<136 && y<91)couleur=6; @@ -628,47 +505,179 @@ if (x>=272 && x<340 && y>180)couleur=1; if (x>=340 && x<408 && y>180)couleur=3; if (x>=408 && x<480 && y>180)couleur=6; - + } + + //GOMME + if (x<=396 && x>=355 && y<=267 && y>=254 ) + { + p=0; + couleur = 0; } + + //EFFACE TOUT + if (x<=438 && x>=410 && y<=267 && y>=254 ) + { + x=0; + y=0; + BSP_LCD_Clear(LCD_COLOR_WHITE); + matrix.clear(); + } + + //RETOUR PAGE ACCUEIL + if ((x>= 458 && x<= 480) && (y>= 240 && y<= 270)) + { + BSP_LCD_Clear(LCD_COLOR_WHITE); + matrix.clear(); + matrix.swap(); + while (!matrix.synchro()); + x = 0; + y = 0; + page = 0; + } + }//FIN IF PAGE == 1 + + + if (page == 2) //PAGE DRAPEAU + { + page_drapeau(); //Affichage de la page drapeau + + //HAUT GAUCHE + if ((x>= 8 && x<= 236) && (y>= 29 && y<= 103)) + { + x = 0; + y = 0; + //ALLEMAGNE + matrix.clear(); + matrix.drawRect(0,10,64,21,3); + matrix.drawRect(0,21,64,32,1); + matrix.swap(); + while (!matrix.synchro()); + } + + // HAUT DROITE + else if ((x>= 244 && x<= 472) && (y>= 29 && y<= 103)) + { + x = 0; + y = 0; + // BELGE + matrix.clear(); + matrix.drawRect(21,0,43,64,3); + matrix.drawRect(43,0,64,64,1); + matrix.swap(); + while (!matrix.synchro()); + } + + // MILIEU GAUCHE + else if ((x>= 8 && x<= 236) && (y>= 110 && y<= 184)) + { + x = 0; + y = 0; + //BENIN + matrix.clear(); + matrix.drawRect(0,0,21,64,2); + matrix.drawRect(21,0,64,16,3); + matrix.drawRect(21,16,64,32,1); + matrix.swap(); + while (!matrix.synchro()); + } - + // MILIEU DROITE + else if ((x>= 244 && x<= 472) && (y>= 110 && y<= 184)) + { + x = 0; + y = 0; + //MULTICOLOR + matrix.clear();//1 rouge; 2 vert; 3 jaune; 4 bleu; 5 violet; 6 cyan; 7 blanc + matrix.drawRect(0,0,64,4,7); + matrix.drawRect(0,4,64,8,1); + matrix.drawRect(0,8,64,12,3); + matrix.drawRect(0,12,64,16,2); + matrix.drawRect(0,16,64,20,4); + matrix.drawRect(0,20,64,24,6); + matrix.drawRect(0,24,64,28,5); + matrix.drawRect(0,28,64,32,7); + matrix.swap(); + while (!matrix.synchro()); + } + + // BAS GAUCHE + else if ((x>= 8 && x<= 236) && (y>= 192 && y<= 266)) + { + x = 0; + y = 0; + //FRANCE + matrix.clear(); + matrix.drawRect(0,0,21,64,4); + matrix.drawRect(21,0,43,64,7); + matrix.drawRect(43,0,64,64,1); + matrix.swap(); + while (!matrix.synchro()); + } + + + // BAS DROITE + else if ((x>= 244 && x<= 472) && (y>= 192 && y<= 266)) + { + x = 0; + y = 0; + //ITALIE + matrix.clear(); + matrix.drawRect(0,0,21,64,2); + matrix.drawRect(21,0,43,64,7); + matrix.drawRect(43,0,64,64,1); + matrix.swap(); + while (!matrix.synchro()); + } + + if ((page==2)&&(x>= 458 && x<= 480) && (y>= 0 && y<= 22)) + { + BSP_LCD_Clear(LCD_COLOR_WHITE); + matrix.clear(); + matrix.swap(); + while (!matrix.synchro()); + x = 0; + y = 0; + page = 0; + } + + } // FIN IF == 2 + }// FIN WHILE }// FIN MAIN -///////////////////////// FIN DU MAIN (L247-L691)//////////////////////////////////////// - - - +///////////////////////// FIN DU MAIN (L262-L652)//////////////////////////////////////// -//////////////////// FONCTIONS PAGES (L700-L773) /////////////////////////////////////////////////////// +//////////////////// FONCTIONS PAGES (L659-L737) /////////////////////////////////////////////////////// void page_accueil() { - BSP_LCD_SetTextColor(LCD_COLOR_BLACK); - BSP_LCD_DrawRect(10, 10, 225, 225); //Bouton dessin + BSP_LCD_SetTextColor(LCD_COLOR_BLACK); //Couleur du texte + BSP_LCD_DrawRect(10, 10, 225, 225); //Bouton dessin BSP_LCD_DrawRect(245, 10, 225, 225); //Bouton drapeau - sprintf((char*)text, "DESSIN"); - BSP_LCD_DisplayStringAt(95, LINE(20), (uint8_t *)&text, LEFT_MODE); - drawImage_dessin(15,15); + sprintf((char*)text, "DESSIN"); //texte a ecrire + BSP_LCD_DisplayStringAt(95, LINE(20), (uint8_t *)&text, LEFT_MODE); //position du texte + drawImage_dessin(15,15); //fonction de dessin de l'image "dessin" - sprintf((char*)text,"DRAPEAU"); - BSP_LCD_DisplayStringAt(120, LINE(20), (uint8_t *)&text, CENTER_MODE); - drawImage_drapeau(250, 15); - } + sprintf((char*)text,"DRAPEAU"); //texte a ecrire + BSP_LCD_DisplayStringAt(120, LINE(20), (uint8_t *)&text, CENTER_MODE); //position du texte + drawImage_drapeau(250, 15); //fonction de dessin de l'image "drapeau" + } void page_dessin() { - // ROUGE + //AFFICHAGE DE LA BARRE DE COMMANDE + + // ROUGE BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillRect(2,242,41, 28); //VERT @@ -708,21 +717,24 @@ } void page_drapeau() -{ - // Au dessus 22px de la barre + 7// - /* 8px */ BSP_LCD_DrawRect(8, 29, 228, 74); /* 8px */ BSP_LCD_DrawRect(244, 29, 228, 74); /* 8px */ - drawImage_allemagne(10,31); /* 7px */ drawImage_belgique (246,31); - - /* 8px */ BSP_LCD_DrawRect(8, 110, 228, 74); /* 8px */ BSP_LCD_DrawRect(244, 110, 228, 74); /* 8px */ - drawImage_benin (10,111); /* 7px */ drawImage_lgbt (246,111); - - /* 8px */ BSP_LCD_DrawRect(8, 191, 228, 73); /* 8px */ BSP_LCD_DrawRect(244, 191, 228, 73); /* 8px */ - drawImage_france (10,192); drawImage_italie (246,192); - - drawImage_fleche(447,0);// RETOUR +{ + BSP_LCD_DrawRect (8, 29, 228, 74); + BSP_LCD_DrawRect (8, 110,228, 74); + BSP_LCD_DrawRect (8, 191,228, 73); + BSP_LCD_DrawRect (244,29, 228, 74); + BSP_LCD_DrawRect (244,110,228, 74); + BSP_LCD_DrawRect (244,191,228, 73); + + drawImage_allemagne(10,31); + drawImage_belgique (246,31); + drawImage_benin (10,111); + drawImage_lgbt (246,111); + drawImage_france (10,192); + drawImage_italie (246,192); + drawImage_fleche (447,0); // RETOUR } -//////////////////// FIN DES FONCTIONS PAGES (L693-L766) /////////////////////////////////////////////////////// +//////////////////// FIN DES FONCTIONS PAGES (L659-L737) ///////////////////////////////////////////////////////