Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_TFTLCD.h>
- #include <Adafruit_GFX.h>
- #include <TouchScreen.h>
- #define LCD_CS A3
- #define LCD_CD A2
- #define LCD_WR A1
- #define LCD_RD A0
- #define LCD_RESET A4
- #define TS_MINX 143
- #define TS_MINY 126
- #define TS_MAXX 947
- #define TS_MAXY 902
- #define YP A2
- #define XM A3
- #define YM 8
- #define XP 9
- #define BLACK 0x0000
- #define RED 0xF800
- #define WHITE 0xFFFF
- Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
- boolean buttonEnabled = true;
- void setup() {
- tft.reset();
- tft.begin(0x9325);
- tft.setRotation(1);
- tft.fillScreen(BLACK); // Background screen
- tft.drawRect(0,0,319,240,WHITE);
- tft.setCursor(40,80);
- tft.setTextColor(WHITE); // Text color
- tft.setTextSize(2);
- tft.print(" 2.8 inch TFT Shield"); // Text above the button
- tft.fillRect(60,180, 200, 40, RED);
- tft.drawRect(60,180,200,40,WHITE);
- tft.setCursor(80,188);
- tft.setTextColor(WHITE);
- tft.setTextSize(3);
- tft.print("Press me!"); // Button Text
- }
- void loop() {
- TSPoint p = ts.getPoint();
- if (p.z > ts.pressureThreshhold) {
- p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
- p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
- if (p.x > 60 && p.x < 260 && p.y > 180 && p.y < 220 && buttonEnabled) {
- buttonEnabled = false;
- pinMode(XM, OUTPUT);
- pinMode(YP, OUTPUT);
- tft.fillScreen(BLACK);
- tft.drawRect(0,0,319,240,WHITE);
- tft.setCursor(20,90);
- tft.setTextColor(WHITE);
- tft.setTextSize(2);
- tft.print("Your display is working!"); // Text after the button press
- }
- delay(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement