Example Code for Arduino-Touch Function
Last revision 2025/12/25
In this section, we'll explain how to use the touch function
Hardware Preparation
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- Download the DFRobot_TELEMATICS_3.5-_TFT_Touch_LCD_Shield library: DFRobot_TELEMATICS_3.5-_TFT_Touch_LCD_Shield library
- About how to install the library?
Note: This library only works on Classic Arduino IDE 1.0.x)
Sample Code
#include <Arduino.h>
#include <SPI.h>
#include <MultiLCD.h>
#include "touch.h"
LCD_R61581 lcd;
void setup(){
lcd.begin();
lcd.setFontSize(FONT_SIZE_MEDIUM); //set font size
lcd.setColor(RGB16_YELLOW); //set strings color
lcd.println("DFRobot");
lcd.println("TELEMATICS LCD SHIELD V1.0");
lcd.println();
lcd.setColor(RGB16_WHITE);
touch.init();
}
void loop(){
lcd.setCursor(0, 8);
int x, y;
if ( touch.read(x, y) ){
lcd.print("X:");
lcd.print(x);
lcd.print(" Y:");
lcd.print(y);
lcd.print(" ");
} else {
lcd.print(" ");
}
}
Result
The yellow text "DFRobot" and "TELEMATICS LCD SHIELD V1.0" is permanently displayed on the screen.
Touching any position on the screen will show real-time X/Y coordinates in white at the specified position; the coordinate area is cleared when the touch is released.
Was this article helpful?
