Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. /***************************************************
  2.   This is our touchscreen painting example for the Adafruit TFT FeatherWing
  3.   ----> http://www.adafruit.com/products/3315
  4.   Check out the links above for our tutorials and wiring diagrams
  5.   Adafruit invests time and resources providing this open source code,
  6.   please support Adafruit and open-source hardware by purchasing
  7.   products from Adafruit!
  8.   Written by Limor Fried/Ladyada for Adafruit Industries.
  9.   MIT license, all text above must be included in any redistribution
  10.  ****************************************************/
  11.  
  12. #include <SPI.h>
  13. #include <Wire.h>      // this is needed even tho we aren't using it
  14.  
  15.  
  16. #include <Adafruit_GFX.h>    // Core graphics library
  17. #include "Adafruit_ILI9341.h" // Hardware-specific library
  18. #include <XPT2046_Touchscreen.h>
  19.  
  20.  
  21.  
  22.  
  23. #define TFT_CS   4
  24. #define XPT2046_CS 16
  25. #define XPT2046_DC 0
  26. #define TFT_DC   2
  27. #define SD_CS    5
  28.  
  29.  
  30.  
  31. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
  32. XPT2046_Touchscreen ts(XPT2046_CS);
  33.  
  34. class Button
  35. {
  36.   int width;
  37.   int height;
  38.   int posX;
  39.   int posY;
  40.   bool shown;
  41.  
  42. public:
  43.   Button (int, int, int, int, bool);
  44.   int draw()
  45.   {
  46.     tft.fillRoundRect(posX, posY, width, height, 8, ILI9341_RED);
  47.     tft.drawRoundRect(posX, posY, width, height, 8, ILI9341_BLACK);
  48.   }
  49. };
  50.  
  51. Button::Button (int a, int b, int c, int d, bool vis) {
  52.  
  53.   posX = a;
  54.   posY = b;
  55.   width = c;
  56.   height = d;
  57.   shown = vis;
  58.  
  59. }
  60.  
  61. Button getTouch()
  62. {
  63.  
  64.  
  65.  
  66. }
  67.  
  68. Button array[3];
  69. // This is calibration data for the raw touch data to the screen coordinates
  70. #define TS_MINX 3800
  71. #define TS_MAXX 300
  72. #define TS_MINY 350
  73. #define TS_MAXY 3750
  74. #define BUFFPIXEL 20
  75.  
  76. #define PENRADIUS 3
  77. #define WIDTH 320
  78. #define HEIGHT 240
  79. #define PADDING 40
  80.  
  81.  
  82. int millis1;
  83. int millis2;
  84.  
  85.  
  86.  
  87.  
  88. void setup(void) {
  89.   Serial.begin(115200);
  90.  
  91.  
  92.   delay(10);
  93.   Serial.println("FeatherWing TFT");
  94.     ts.begin();
  95.  
  96.  
  97.  
  98.   tft.begin();
  99.   tft.setRotation(3);
  100.   tft.fillScreen(ILI9341_WHITE);
  101.  
  102.  
  103.  
  104.  
  105.  
  106.   yield();
  107. /*
  108.   Serial.print("Initializing SD card...");
  109.   if (!SD.begin(SD_CS)) {
  110.     Serial.println("failed!");
  111.   }
  112.   Serial.println("OK!");
  113.   */
  114.   Button Button1(0, 0, 100, 100);
  115.   Button1.draw();
  116.  
  117.  
  118.  
  119.  
  120.  
  121. }
  122.  
  123. void loop()
  124. {
  125.   delay(10);
  126. if (ts.touched()) {
  127.  
  128.     TS_Point p = ts.getPoint();
  129.  
  130.  
  131.     p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
  132.     p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
  133.  
  134.     Serial.print("Pressure = ");
  135.     Serial.print(p.z);
  136.     Serial.print(", x = ");
  137.     Serial.print(p.x);
  138.     Serial.print(", y = ");
  139.     Serial.print(p.y);
  140.     Serial.println("");
  141.     }
  142.   }
  143.  
  144.   // Retrieve a point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement