PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 satır
1.7KB

  1. #include <ILI9341_t3.h>
  2. #include <font_Arial.h> // from ILI9341_t3
  3. #include <XPT2046_Touchscreen.h>
  4. #include <SPI.h>
  5. #define CS_PIN 8
  6. #define TFT_DC 9
  7. #define TFT_CS 10
  8. // MOSI=11, MISO=12, SCK=13
  9. XPT2046_Touchscreen ts(CS_PIN);
  10. #define TIRQ_PIN 2
  11. //XPT2046_Touchscreen ts(CS_PIN); // Param 2 - NULL - No interrupts
  12. //XPT2046_Touchscreen ts(CS_PIN, 255); // Param 2 - 255 - No interrupts
  13. //XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
  14. ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
  15. void setup() {
  16. Serial.begin(38400);
  17. tft.begin();
  18. tft.setRotation(1);
  19. tft.fillScreen(ILI9341_BLACK);
  20. ts.begin();
  21. ts.setRotation(1);
  22. while (!Serial && (millis() <= 1000));
  23. }
  24. boolean wastouched = true;
  25. void loop() {
  26. boolean istouched = ts.touched();
  27. if (istouched) {
  28. TS_Point p = ts.getPoint();
  29. if (!wastouched) {
  30. tft.fillScreen(ILI9341_BLACK);
  31. tft.setTextColor(ILI9341_YELLOW);
  32. tft.setFont(Arial_60);
  33. tft.setCursor(60, 80);
  34. tft.print("Touch");
  35. }
  36. tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
  37. tft.setTextColor(ILI9341_GREEN);
  38. tft.setFont(Arial_24);
  39. tft.setCursor(100, 150);
  40. tft.print("X = ");
  41. tft.print(p.x);
  42. tft.setCursor(100, 180);
  43. tft.print("Y = ");
  44. tft.print(p.y);
  45. Serial.print(", x = ");
  46. Serial.print(p.x);
  47. Serial.print(", y = ");
  48. Serial.println(p.y);
  49. } else {
  50. if (wastouched) {
  51. tft.fillScreen(ILI9341_BLACK);
  52. tft.setTextColor(ILI9341_RED);
  53. tft.setFont(Arial_48);
  54. tft.setCursor(120, 50);
  55. tft.print("No");
  56. tft.setCursor(80, 120);
  57. tft.print("Touch");
  58. }
  59. Serial.println("no touch");
  60. }
  61. wastouched = istouched;
  62. delay(100);
  63. }