Example Code for Arduino - UI gesture

This is a gesture reading example. Perform operations in the gesture area: click, double click, long press, upwards slide, down slide, left slide, right slide.

Precautions Before Use

  • The GDI interface must be used with a main controller that has a GDI interface.
  • It is recommended to use Arduino 1.8.10 or a later version.
  • Poor contact of the SD card slot may cause initialization failure; reinserting the SD card may resolve the issue.

Hardware Preparation

Software Preparation

Hardware Connection

GDI Cable Connection Method

2.54 Pin Header Connection Method

Display Pin Controller Pin
VCC 3V3
GND GND
CLK SCK
SI MO
SO MI
SCR_CS D6
RST D3
DC D2
BL D13
SCL SCL
SDA SDA
INT D11
SD_CS Do not use / Leave unconnected
TP_R D10
  • All demonstration demos for this product are stored in the DFRobot_GDL->example->basic folder.
  • Before burning the demo, enable the corresponding instantiation function (DFRobot_ST7365P_320x480_HW_SPI).

Sample Code

Program Description: This is a gesture reading example. Perform operations in the gesture area: click, double click, long press, upwards slide, down slide, left slide, right slide.

#include "DFRobot_UI.h"
#include "Arduino.h"
#include "DFRobot_GDL.h"
#include "DFRobot_Touch.h"
/*ESP32 and ESP8266*/
#if defined(ESP32)
#define TFT_DC    D2     
#define TFT_CS    D6      
#define TFT_RST   D3    
#define TFT_BL    D13   
#define TOUCH_RST D10
#define TOUCH_INT D11
#endif

DFRobot_Touch_GT911_IPS touch(0X5D,TOUCH_RST,TOUCH_INT);
DFRobot_ST7365P_320x480_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST,/*bl=*/TFT_BL);

DFRobot_UI ui(&screen, &touch);

void setup()
{
  Serial.begin(9600);
  ui.begin();
  // Set the UI theme, there are two themes to choose from: CLASSIC and MODERN.
  ui.setTheme(DFRobot_UI::MODERN);
  
  //Create a text box control
  DFRobot_UI::sTextBox_t &tb = ui.creatText();
  //Create a text box control on the screen and draw the text box according to the customized or initialized parameters
  ui.draw(&tb);
  /**
   * @brief Set the touch gesture recognition area
   */
  ui.setGestureArea(/*x=*/screen.width()/2-75,/*y=*/200,/*width=*/150,/*height=*/200);
  while(true){
     //refresh
    ui.refresh();
    // getGestures(): Get gesture
    switch(ui.getGestures()){
      //setText:let the text box display a string
      case ui.SUPGLIDE : tb.setText("upwards slide"); break;
      case ui.SDOWNGLIDE : tb.setText("down slide"); break;
      case ui.SLEFTGLIDE : tb.setText("left slide"); break;
      case ui.SRIGHTGLIDE : tb.setText("right slide"); break;
      case ui.DLONGPRESSED : tb.setText("long press"); break;
      case ui.SCLICK : tb.setText("click"); break;
      case ui.DDOUBLECLICK : tb.setText("double click"); break;
      default  :  break;
      }
  }
}

void loop()
{
  
}

Was this article helpful?

TOP