ST / Mbed 2 deprecated DISCO_F413ZH-touch-screen-demo

Dependencies:   BSP_DISCO_F413ZH mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stm32f413h_discovery.h"
00003 #include "stm32f413h_discovery_ts.h"
00004 #include "stm32f413h_discovery_lcd.h"
00005 
00006 TS_StateTypeDef  TS_State = {0};
00007 
00008 int main()
00009 {
00010     uint16_t x1, y1;
00011 
00012     BSP_LCD_Init();
00013 
00014     /* Touchscreen initialization */
00015     if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) {
00016         printf("BSP_TS_Init error\n");
00017     }
00018 
00019     /* Clear the LCD */
00020     BSP_LCD_Clear(LCD_COLOR_WHITE);
00021 
00022     /* Set Touchscreen Demo1 description */
00023     BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
00024     BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40);
00025     BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
00026     BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
00027     BSP_LCD_SetFont(&Font16);
00028     BSP_LCD_DisplayStringAt(0, 15, (uint8_t *)"Touch the screen", CENTER_MODE);
00029 
00030     while (1) {
00031         BSP_TS_GetState(&TS_State);
00032         if(TS_State.touchDetected) {
00033             /* One or dual touch have been detected          */
00034 
00035             /* Get X and Y position of the first touch post calibrated */
00036             x1 = TS_State.touchX[0];
00037             y1 = TS_State.touchY[0];
00038             printf("Touch Detected x=%d y=%d\n", x1, y1);
00039 
00040             BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
00041             BSP_LCD_FillCircle(x1, y1, 20);
00042 
00043             wait_ms(10);
00044         }
00045     }
00046 }