/*############################################################# Program Name : ex2_F469NI_TSFaces 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. There are 3 buttons to select which facial expression should be displayed. Requirements : * DISCO-F469NI Board Circuit : * NONE ##############################################################*/ #include "mbed.h" #include "TS_DISCO_F469NI.h" #include "LCD_DISCO_F469NI.h" void DrawSmile(void); void DrawSad(void); void DrawFrown(void); void DrawSmileButton(void); void DrawFrownButton(void); void DrawSadButton(void); 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; uint8_t status; lcd.Clear(LCD_COLOR_BLACK); status = ts.Init(800, 480); //initialize the touchscreen for a 240x320 display if (status != TS_OK) { //test if the initialization was ERROR 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); while(1); //do not continue if there is an error } DrawSmile(); DrawSmileButton(); DrawFrownButton(); DrawSadButton(); 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 y = TS_State.touchY[0]; //read the y value if((x >= 60) && (x <= 180) && (y >= 140) && (y <= 180)) //if the x and y touch position is within the bounds of the Smile button DrawSmile(); else if((x >= 60) && (x <= 180) && (y >= 200) && (y <= 240)) //if the x and y touch position is within the bounds of the Frown button DrawFrown(); else if((x >= 60) && (x <= 180) && (y >= 260) && (y <= 300)) //if the x and y touch position is within the bounds of the Sad button DrawSad(); else { //do nothing when not incorrect touch position } wait(0.01); //delay to prevent contact bounce on the screen } } } void DrawSmile(void) { uint16_t x, y; x = 120; y = 60; /* Draw face */ lcd.SetTextColor(LCD_COLOR_MAGENTA); lcd.FillCircle(x,y,50); /* Draw eyes */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.FillCircle(x-20,y-20,8); lcd.FillCircle(x+20,y-20,8); /* Draw mouth */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.DrawLine(x-10,y+20,x+10,y+20); lcd.DrawLine(x-10,y+20,x-20,y+10); lcd.DrawLine(x+10,y+20,x+20,y+10); } void DrawSad(void) { uint16_t x, y; x = 120; y = 60; /* Draw face */ lcd.SetTextColor(LCD_COLOR_MAGENTA); lcd.FillCircle(x,y,50); /* Draw eyes */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.FillCircle(x-20,y-20,8); lcd.FillCircle(x+20,y-20,8); /* Draw mouth */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.DrawLine(x-10,y+10,x+10,y+10); lcd.DrawLine(x-10,y+10,x-20,y+20); lcd.DrawLine(x+10,y+10,x+20,y+20); } void DrawFrown(void) { uint16_t x, y; x = 120; y = 60; /* Draw face */ lcd.SetTextColor(LCD_COLOR_MAGENTA); lcd.FillCircle(x,y,50); /* Draw eyes */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.FillCircle(x-20,y-20,8); lcd.FillCircle(x+20,y-20,8); /* Draw mouth */ lcd.SetTextColor(LCD_COLOR_YELLOW); lcd.DrawLine(x-20,y+15,x+20,y+15); } void DrawSmileButton(void) { uint16_t x, y; x = 60; y = 140; /* Draw rectangle for button */ lcd.SetTextColor(LCD_COLOR_WHITE); lcd.FillRect(x, y, 120, 40); /* Draw text */ lcd.SetFont(&Font24); lcd.SetTextColor(LCD_COLOR_BLUE); lcd.DisplayStringAt(75,y+10,(uint8_t *)"SMILE", LEFT_MODE); } void DrawFrownButton(void) { uint16_t x, y; x = 60; y = 200; /* Draw rectangle for button */ lcd.SetTextColor(LCD_COLOR_WHITE); lcd.FillRect(x, y, 120, 40); /* Draw text */ lcd.SetFont(&Font24); lcd.SetTextColor(LCD_COLOR_BLUE); lcd.DisplayStringAt(75,y+10,(uint8_t *)"FROWN", LEFT_MODE); } void DrawSadButton(void) { uint16_t x, y; x = 60; y = 260; /* Draw rectangle for button */ lcd.SetTextColor(LCD_COLOR_WHITE); lcd.FillRect(x, y, 120, 40); /* Draw text */ lcd.SetFont(&Font24); lcd.SetTextColor(LCD_COLOR_BLUE); lcd.DisplayStringAt(95,y+10,(uint8_t *)"SAD", LEFT_MODE); }