/*############################################################# Program Name : ex1_F469NI_TSDisplayXY Author : Grant Phillips Date Modified : 22/09/2016 Compiler : ARMmbed Tested On : DISCO-F469NI Description : Example program that demonstrates the use of the DSI TFT LCD touchscreen panel. When touched, the x and y variables indicate the position of the touch on the screen. This example demonstrates only a single touch. The DISCO-F469NI touchscreen, however, allows for multiple simultaneous touches. See the default ARMmbed touchscreen template for info on how to implement this. Requirements : * DISCO-F469NI Board Circuit : * NONE ##############################################################*/ #include "mbed.h" #include "TS_DISCO_F469NI.h" #include "LCD_DISCO_F469NI.h" LCD_DISCO_F469NI lcd; //Create a LCD_DISCO_F469NI object TS_DISCO_F469NI ts; //Create a TS_DISCO_F469NI object int main() { TS_StateTypeDef TS_State; //create a variable to store the state of the touchscreen uint16_t x, y; char text[30]; uint8_t status; lcd.SetFont(&Font20); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"DEMO", CENTER_MODE); wait(1); status = ts.Init(800, 480); //initialize the touchscreen for a 800x480 display if (status != TS_OK) { //test if the initialization was OK lcd.Clear(LCD_COLOR_RED); lcd.SetBackColor(LCD_COLOR_RED); lcd.SetTextColor(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); } else { lcd.Clear(LCD_COLOR_GREEN); lcd.SetBackColor(LCD_COLOR_GREEN); lcd.SetTextColor(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); } wait(1); lcd.Clear(LCD_COLOR_BLUE); lcd.SetBackColor(LCD_COLOR_BLUE); lcd.SetTextColor(LCD_COLOR_WHITE); while(1) { ts.GetState(&TS_State); //Read the status of the touchscreen if (TS_State.touchDetected) { //if the screen was touched x = TS_State.touchX[0]; //read the x value (for 1st touch) y = TS_State.touchY[0]; //read the y value (for 1st touch) sprintf(text, "x=%d y=%d ", x, y); //print x and y values to the text string lcd.DisplayStringAt(0, LINE(0), (uint8_t*)text, LEFT_MODE); //write the text string to the LCD } } }