所以我有一个Arduino MEGA2560和一个TFT屏蔽触摸屏。我使用其中一个示例,只需使用drawRect()
即可在屏幕上显示2个按钮。但是当我按下它们时,如何使这两个盒子做某事呢?我知道这两个盒子的坐标,那么我如何让它们“感觉”触摸并转换到另一个显示屏?也许代码的例子会很有帮助!感谢。
我目前的代码如下:你可以添加必要的部分。
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
Serial.begin(9600);
progmemPrintln(PSTR("TFT LCD"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
progmemPrintln(PSTR("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
progmemPrintln(PSTR("Found ILI9328 LCD driver"));
} else if(identifier == 0x7575) {
progmemPrintln(PSTR("Found HX8347G LCD driver"));
} else {
progmemPrint(PSTR("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h)."));
progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!"));
progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring"));
progmemPrintln(PSTR("matches the tutorial."));
return;
}
tft.begin(identifier);
progmemPrint(PSTR("Text "));
Serial.println(startText());
delay(0);
progmemPrintln(PSTR("Done!"));
}
void loop(void) {
startText();
delay(9999999);
}
unsigned long startText() {
tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.println();
tft.println();
tft.setTextColor(GREEN); tft.setTextSize(2.8);
tft.println("Welcome ");
tft.println();
tft.setTextColor(WHITE); tft.setTextSize(2.5);
tft.println();
tft.drawRect(5, 150, 110, 110, YELLOW);
tft.drawRect(130, 150, 110, 110, RED);
tft.setCursor(155, 170);
tft.setTextColor(RED);
tft.println("OFF");
tft.fillRect(5, 150, 110, 110, YELLOW);
tft.fillRect(13, 158, 94, 94, BLACK);
tft.setTextColor(GREEN);
tft.setCursor(20, 170);
tft.println("ON");
return micros() - start;
}
// Copy string from flash to serial port
// Source string MUST be inside a PSTR() declaration!
void progmemPrint(const char *str) {
char c;
while(c = pgm_read_byte(str++)) Serial.print(c);
}
// Same as above, with trailing newline
void progmemPrintln(const char *str) {
progmemPrint(str);
Serial.println();
}
答案 0 :(得分:1)
您需要触摸屏lib
#include <TouchScreen.h>
//inside loop
TSPoint p = ts.getPoint();
// Retrieve a point
p = ts.getPoint();
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
答案 1 :(得分:-2)
这是一个UART TFT LCD,它支持WYSIWYG编辑器在PC上构建GUI并通过USB下载。
它可以通过UART由Arduino控制,所以只需使用Serial.print()就可以显示许多图像。您甚至可以自己构建Font并下载到LCD。
请参阅https://www.indiegogo.com/projects/nextion-a-cost-effective-high-performance-tft-hmi/x/4467372