Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************
- This is our touchscreen painting example for the Adafruit TFT FeatherWing
- ----> http://www.adafruit.com/products/3315
- Check out the links above for our tutorials and wiring diagrams
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- MIT license, all text above must be included in any redistribution
- ****************************************************/
- #include <SPI.h>
- #include <Wire.h> // this is needed even tho we aren't using it
- #include <Adafruit_GFX.h> // Core graphics library
- #include "Adafruit_ILI9341.h" // Hardware-specific library
- #include <XPT2046_Touchscreen.h>
- #define TFT_CS 4
- #define XPT2046_CS 16
- #define XPT2046_DC 0
- #define TFT_DC 2
- #define SD_CS 5
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
- XPT2046_Touchscreen ts(XPT2046_CS);
- class Button
- {
- int width;
- int height;
- int posX;
- int posY;
- bool shown;
- public:
- Button (int, int, int, int, bool);
- int draw()
- {
- tft.fillRoundRect(posX, posY, width, height, 8, ILI9341_RED);
- tft.drawRoundRect(posX, posY, width, height, 8, ILI9341_BLACK);
- }
- };
- Button::Button (int a, int b, int c, int d, bool vis) {
- posX = a;
- posY = b;
- width = c;
- height = d;
- shown = vis;
- }
- Button getTouch()
- {
- }
- Button array[3];
- // This is calibration data for the raw touch data to the screen coordinates
- #define TS_MINX 3800
- #define TS_MAXX 300
- #define TS_MINY 350
- #define TS_MAXY 3750
- #define BUFFPIXEL 20
- #define PENRADIUS 3
- #define WIDTH 320
- #define HEIGHT 240
- #define PADDING 40
- int millis1;
- int millis2;
- void setup(void) {
- Serial.begin(115200);
- delay(10);
- Serial.println("FeatherWing TFT");
- ts.begin();
- tft.begin();
- tft.setRotation(3);
- tft.fillScreen(ILI9341_WHITE);
- yield();
- /*
- Serial.print("Initializing SD card...");
- if (!SD.begin(SD_CS)) {
- Serial.println("failed!");
- }
- Serial.println("OK!");
- */
- Button Button1(0, 0, 100, 100);
- Button1.draw();
- }
- void loop()
- {
- delay(10);
- if (ts.touched()) {
- TS_Point p = ts.getPoint();
- p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
- p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
- Serial.print("Pressure = ");
- Serial.print(p.z);
- Serial.print(", x = ");
- Serial.print(p.x);
- Serial.print(", y = ");
- Serial.print(p.y);
- Serial.println("");
- }
- }
- // Retrieve a point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement