https://www.youtube.com/watch?v=Js4wykWY6zg
https://www.youtube.com/watch?v=IIQlGHpUZXw
TFT LCD 2.4" Touch screen shield tutorial for beginners
1,061 views
Touch Screen _Calibr_native,ino uploded then check Serial Monitor
// Paint example specifically for the TFTLCD breakout board.
// If using the Arduino shield, use the tftpaint_shield.pde sketch instead!
// DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO
// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega
// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End
#if defined(_SAM3X8E_)
#undef_FlashStringHelper::F(string_literal)
#define F(String_literal) string_literal
#endif
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#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) {
tft.reset();
tft.begin(0x9328);
tft.setRotation(0);
tft.fillScreen(BLACK);
tft.fillRect(20, 40, 80, 80, RED);
tft.fillRect(130, 40, 80, 80, GREEN);
pinMode(13, OUTPUT);
}
void loop()
{
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());;
if(p.y > 20 && p.y < 100 && p.x >40 && p.x <120){
tft.fillRect(0, 180, 300, 300, BLACK);
tft.setCursor(20,180);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.print("Green pressed");
digitalWrite(13, HIGH);
}
else if (p.x > 130 && p.x < 210 && p.y >40 && p.y <120){
tft.fillRect(0, 180, 300, 300, BLACK);
tft.setCursor(0,180);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.print("Red pressed");
digitalWrite(13, LOW);
}
}
}
No comments:
Post a Comment