
Projet Interfaçage
Dependencies: BSP_DISCO_F746NG
Revision 4:bb9c545c6d7f, committed 2021-06-22
- Comitter:
- liroy_theilor
- Date:
- Tue Jun 22 12:38:21 2021 +0000
- Parent:
- 3:9f66aabe7b3b
- Commit message:
- Programme
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 20 11:49:15 2019 +0100 +++ b/main.cpp Tue Jun 22 12:38:21 2021 +0000 @@ -2,11 +2,26 @@ #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_ts.h" + char affiche[30]; + int lecture; + int compteur=0; + bool obstak=false; + int colis=0; + + void capteurTOR (); + + +PwmOut servo(D1); // Servomoteur +DigitalIn capteur(A0); // Capteur de lettre + + int main() { TS_StateTypeDef TS_State; uint16_t x, y; - uint8_t text[30]; + uint8_t text[30]; + int i; + char PSWD[4]; uint8_t status; uint8_t idx; uint8_t cleared = 0; @@ -20,12 +35,15 @@ HAL_Delay(1000); status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); - if (status != TS_OK) { + if (status != TS_OK) + { BSP_LCD_Clear(LCD_COLOR_RED); BSP_LCD_SetBackColor(LCD_COLOR_RED); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); - } else { + } + else + { BSP_LCD_Clear(LCD_COLOR_GREEN); BSP_LCD_SetBackColor(LCD_COLOR_GREEN); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); @@ -34,10 +52,100 @@ HAL_Delay(1000); BSP_LCD_SetFont(&Font12); - BSP_LCD_SetBackColor(LCD_COLOR_BLUE); + + + //COULEUR DU FOND D'écran + BSP_LCD_SetBackColor(LCD_COLOR_DARKCYAN); + // COULEUR ECRITURE BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + BSP_LCD_Clear(LCD_COLOR_DARKCYAN ); + + sprintf((char*)text, "BOITES AUX LETTRES "); + BSP_LCD_DisplayStringAt(20, LINE(1), (uint8_t *)&text, CENTER_MODE); + + sprintf((char*)text, "THEILOR LIROY "); + BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, RIGHT_MODE); + + + + + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "1"); + BSP_LCD_DisplayStringAt(211, LINE(8), (uint8_t *)&text, LEFT_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "2"); + BSP_LCD_DisplayStringAt(25, LINE(8), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "3"); + BSP_LCD_DisplayStringAt(70, LINE(8), (uint8_t *)&text, CENTER_MODE); + + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "4"); + BSP_LCD_DisplayStringAt(211, LINE(11), (uint8_t *)&text, LEFT_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "5"); + BSP_LCD_DisplayStringAt(25, LINE(11), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "6"); + BSP_LCD_DisplayStringAt(70, LINE(11), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "7"); + BSP_LCD_DisplayStringAt(211, LINE(14), (uint8_t *)&text, LEFT_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "8"); + BSP_LCD_DisplayStringAt(25, LINE(14), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "9"); + BSP_LCD_DisplayStringAt(70, LINE(14), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetFont(&Font16); + sprintf((char*)text, "0"); + BSP_LCD_DisplayStringAt(18, LINE(16), (uint8_t *)&text, CENTER_MODE); + + BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); + //Position du cadre + BSP_LCD_DrawRect(200, 60, 100 ,40); + + // CLAVIER + + // BSP_LCD_DrawRect(150, 150, 230,120); + + //LIGNE 1 + BSP_LCD_DrawCircle(215, 140,20); + BSP_LCD_DrawCircle(260, 140,20); + BSP_LCD_DrawCircle(305, 140,20); + + // LIGNE 2 + + BSP_LCD_DrawCircle(215, 182,20); + BSP_LCD_DrawCircle(260,182,20); + BSP_LCD_DrawCircle(305, 182,20); + + // LIGNE 3 + BSP_LCD_DrawCircle(215, 224,20); + BSP_LCD_DrawCircle(260, 224,20); + BSP_LCD_DrawCircle(305, 224,20); + BSP_LCD_DrawRect(220, 249, 60,30); + + servo.pulsewidth_us (2000); while(1) { + BSP_LCD_SetFont(&Font12); + + + capteurTOR(); + + + BSP_TS_GetState(&TS_State); if (TS_State.touchDetected) { @@ -51,24 +159,231 @@ cleared = 0; - sprintf((char*)text, "Touches: %d", TS_State.touchDetected); - BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + // sprintf((char*)text, "Touches: %d", TS_State.touchDetected); + // BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); for (idx = 0; idx < TS_State.touchDetected; idx++) { x = TS_State.touchX[idx]; y = TS_State.touchY[idx]; - sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); - BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); + // sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); + // BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); + + + + } - BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); + } else { if (!cleared) { - BSP_LCD_Clear(LCD_COLOR_BLUE); + // BSP_LCD_Clear(LCD_COLOR_BLUE); + // sprintf((char*)text, "Touches: 0"); + //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + cleared = 1; + + + + + + + + // TOUCHES 1 + if ((x>= 195&& x<= 235) && (y>= 120 && y<= 160)) + { + sprintf((char*)text, "Touches: 1"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + PSWD[i]='1'; + i++; + + } + + // TOUCHES 2 + if ((x>= 240&& x<= 280) && (y>= 120 && y<= 160)) + { + sprintf((char*)text, "Touches: 2"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + PSWD[i]='2'; + i++; + } + // TOUCHES 3 + if ((x>= 285&& x<= 325) && (y>= 120 && y<= 160)) + { + sprintf((char*)text, "Touches: 3"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + PSWD[i]='3'; + i++; + } + + // TOUCHES 4 + if ((x>= 195&& x<= 235) && (y>= 162 && y<= 202)) + { + sprintf((char*)text, "Touches: 4"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + PSWD[i]='4'; + i++; + + } + // TOUCHES 5 + if ((x>= 240&& x<= 280) && (y>= 162 && y<= 202)) + { + sprintf((char*)text, "Touches: 5"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + PSWD[i]='5'; + i++; + } + // TOUCHES 6 + if ((x>= 289&& x<= 318) && (y>= 162&& y<= 202)) + { + sprintf((char*)text, "Touches: 6"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + PSWD[i]='6'; + i++; + + } + + // TOUCHES 7 + if ((x>= 195&& x<= 235) && (y>= 204 && y<= 244)) + { + sprintf((char*)text, "Touches: 7"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + PSWD[i]='7'; + i++; + colis++; + + + } + // TOUCHES 8 + if ((x>= 240&& x<= 280) && (y>= 204 && y<= 244)) + { + sprintf((char*)text, "Touches: 8"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + PSWD[i]='8'; + i++; + } + // TOUCHES 9 + if ((x>= 285&& x<= 325) && (y>= 204&& y<= 244)) + { + sprintf((char*)text, "Touches: 9"); + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + PSWD[i]='9'; + i++; + + } + if ((x>= 220&& x<= 280) && (y>= 250&& y<= 270)) + { sprintf((char*)text, "Touches: 0"); BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); - cleared = 1; + + PSWD[i]='0'; + i++; + } + + + + + + + // CODE LETTRE + + if ((PSWD[0]=='2')&& (PSWD[1]=='6')&& (PSWD[2]=='0')&& (PSWD[3]=='5')) + { + sprintf((char*)text, "CODE BON"); + BSP_LCD_DisplayStringAt(15, LINE(6), (uint8_t *)&text, CENTER_MODE); + + HAL_Delay(1000); + + servo.pulsewidth_us (1000); + // ThisThread::sleep_for(1s); + HAL_Delay(1000); + i=0; + + } + + + //code colis + + else if ((PSWD[0]=='4')&& (PSWD[1]=='3')&& (PSWD[2]=='2')&& (PSWD[3]=='1')) + { + colis++; + sprintf((char*)text, "CODE BON"); + BSP_LCD_DisplayStringAt(15, LINE(6), (uint8_t *)&text, CENTER_MODE); + + + + HAL_Delay(1000); + + servo.pulsewidth_us (1000); + // ThisThread::sleep_for(1s); + HAL_Delay(1000); + i=0; + } + + + + + + + else if (i>=3) + { + + + BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + + } + sprintf((char*)text, "Nombre de colis: %d", colis); + BSP_LCD_DisplayStringAt(0, LINE(10 ), (uint8_t *)&text, LEFT_MODE); + + + compteur=0; + + + if ((PSWD[0]=='1')&& (PSWD[1]=='2')&& (PSWD[2]=='3')&& (PSWD[3]=='4')) + { + sprintf((char*)text, "FERMETURE"); + BSP_LCD_DisplayStringAt(15, LINE(6), (uint8_t *)&text, CENTER_MODE); + HAL_Delay(1000); + + servo.pulsewidth_us (2000); + //ThisThread::sleep_for(1s); + HAL_Delay(1000); + i=0; + } + + + + + } + + + } } } -} + +void capteurTOR (void) + { + lecture =capteur.read(); + + + switch(lecture) + { + case 0: // detection lettres + obstak=true; + break; + + case 1: + if (obstak==true) + { + obstak=false; + compteur++; + } + break; + } + sprintf((char*)affiche, "Nombre de lettre : %d",compteur); + BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)&affiche, LEFT_MODE); + }