Library 11- Button library for ILI9341 LCD and STMPE811 touch controller on STM32F429 Discovery board

If red led is turned on, than bottom 2 buttons work, otherwise they are deadNow we have both, LCD controller and touch controller configured and we can use this. For this purpose i made a library for buttons. This library can draw buttons on LCD and check if touch has been pressed on any enabled button.

Library

Features

  • Set X and Y location of button
  • Set button’s width and height
  • By default 10 buttons are supported
  • Use labels
  • Custom background image or color
  • Border around button
  • Selectable font
  • Disable/Enable button
  • Selectable color for label, background and border

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx I2C
    • STM32F4xx SPI
  • TM
    • defines.h
    • TM DELAY
    • TM ILI9341
    • TM STMPE811
    • TM FONTS

If you have more than 10 buttons, you can make a define in your project’s defines.h file

Main structure

Add buttons

To add button to library, you have to create an instance of TM_ILI9341_Button_t structure first

Then fill instance with settings, like this

and add button to library with

Button operations

Draw button

Enable/disable button

  • By default, every button is enabled
  • If button is disabled, than is ignoring by touch

Delete button

Recognize pressed button

To recognize pressed button, first you have to get touch coordinates. Then, use

and pass touch data as parameter. If any button is pressed, then his id is returned, otherwise -1 is returned.

Example

Example has 3 buttons

  • Button 1 is basic with red background and black border with “Button 1” label
  • Button 2 has disabled label with custom background with black border
  • Button 3 has “Button 3” label with custom background and without border

On board are two leds. If red led is turned on, then buttons 2 and 3 are enabled, otherwise are disabled.

Buttons operations:

  • With button 1 you toggle enable/disable of buttons 2 and 3
  • If button 2 is enabled, then it’s used for turning green led on
  • if button 3 is enabled, then it’s used for turning green led off

Project available on Github, download library below.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!