Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
3,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. #include <Adafruit_TFTLCD.h>
  2. #include <Adafruit_GFX.h>    
  3. #include <TouchScreen.h>
  4.  
  5. #define LCD_CS A3
  6. #define LCD_CD A2
  7. #define LCD_WR A1
  8. #define LCD_RD A0
  9. #define LCD_RESET A4
  10. #define TS_MINX 143
  11. #define TS_MINY 126
  12. #define TS_MAXX 947
  13. #define TS_MAXY 902
  14. #define YP A2  
  15. #define XM A3  
  16. #define YM 8  
  17. #define XP 9  
  18. #define BLACK   0x0000
  19. #define RED     0xF800
  20. #define WHITE   0xFFFF
  21.  
  22. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  23. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  24. boolean buttonEnabled = true;
  25.  
  26. void setup() {
  27.   tft.reset();
  28.   tft.begin(0x9325);
  29.   tft.setRotation(1);
  30.   tft.fillScreen(BLACK); // Background screen
  31.   tft.drawRect(0,0,319,240,WHITE);
  32.   tft.setCursor(40,80);
  33.   tft.setTextColor(WHITE); // Text color
  34.   tft.setTextSize(2);
  35.   tft.print(" 2.8 inch TFT Shield"); // Text above the button
  36.   tft.fillRect(60,180, 200, 40, RED);
  37.   tft.drawRect(60,180,200,40,WHITE);
  38.   tft.setCursor(80,188);
  39.   tft.setTextColor(WHITE);
  40.   tft.setTextSize(3);
  41.   tft.print("Press me!"); // Button Text
  42. }
  43.  
  44. void loop() {
  45.   TSPoint p = ts.getPoint();
  46.  
  47.   if (p.z > ts.pressureThreshhold) {
  48.    p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
  49.    p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
  50.        
  51.   if (p.x > 60 && p.x < 260 && p.y > 180 && p.y < 220 && buttonEnabled) {
  52.     buttonEnabled = false;
  53.     pinMode(XM, OUTPUT);
  54.     pinMode(YP, OUTPUT);
  55.     tft.fillScreen(BLACK);
  56.     tft.drawRect(0,0,319,240,WHITE);
  57.     tft.setCursor(20,90);
  58.     tft.setTextColor(WHITE);
  59.     tft.setTextSize(2);
  60.     tft.print("Your display is working!"); // Text after the button press
  61.    }
  62.    delay(10);  
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement