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.

125 lines
3.0KB

  1. //This example implements a simple sliding On/Off button. The example
  2. // demonstrates drawing and touch operations.
  3. //
  4. //Thanks to Adafruit forums member Asteroid for the original sketch!
  5. //
  6. #include <SPI.h>
  7. #include <Wire.h>
  8. #include <ILI9341_t3.h>
  9. #include <Adafruit_STMPE610.h>
  10. // This is calibration data for the raw touch data to the screen coordinates
  11. #define TS_MINX 150
  12. #define TS_MINY 130
  13. #define TS_MAXX 3800
  14. #define TS_MAXY 4000
  15. #define STMPE_CS 8
  16. Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
  17. #define TFT_CS 10
  18. #define TFT_DC 9
  19. ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
  20. boolean RecordOn = false;
  21. #define FRAME_X 210
  22. #define FRAME_Y 180
  23. #define FRAME_W 100
  24. #define FRAME_H 50
  25. #define REDBUTTON_X FRAME_X
  26. #define REDBUTTON_Y FRAME_Y
  27. #define REDBUTTON_W (FRAME_W/2)
  28. #define REDBUTTON_H FRAME_H
  29. #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
  30. #define GREENBUTTON_Y FRAME_Y
  31. #define GREENBUTTON_W (FRAME_W/2)
  32. #define GREENBUTTON_H FRAME_H
  33. void drawFrame()
  34. {
  35. tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
  36. }
  37. void redBtn()
  38. {
  39. tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
  40. tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
  41. drawFrame();
  42. tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
  43. tft.setTextColor(ILI9341_WHITE);
  44. tft.setTextSize(2);
  45. tft.println("ON");
  46. RecordOn = false;
  47. }
  48. void greenBtn()
  49. {
  50. tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN);
  51. tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
  52. drawFrame();
  53. tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
  54. tft.setTextColor(ILI9341_WHITE);
  55. tft.setTextSize(2);
  56. tft.println("OFF");
  57. RecordOn = true;
  58. }
  59. void setup(void)
  60. {
  61. Serial.begin(9600);
  62. tft.begin();
  63. if (!ts.begin()) {
  64. Serial.println("Unable to start touchscreen.");
  65. }
  66. else {
  67. Serial.println("Touchscreen started.");
  68. }
  69. tft.fillScreen(ILI9341_BLUE);
  70. // origin = left,top landscape (USB left upper)
  71. tft.setRotation(1);
  72. redBtn();
  73. }
  74. void loop()
  75. {
  76. // See if there's any touch data for us
  77. if (!ts.bufferEmpty())
  78. {
  79. // Retrieve a point
  80. TS_Point p = ts.getPoint();
  81. // Scale using the calibration #'s
  82. // and rotate coordinate system
  83. p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
  84. p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
  85. int y = tft.height() - p.x;
  86. int x = p.y;
  87. if (RecordOn)
  88. {
  89. if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
  90. if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
  91. Serial.println("Red btn hit");
  92. redBtn();
  93. }
  94. }
  95. }
  96. else //Record is off (RecordOn == false)
  97. {
  98. if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
  99. if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
  100. Serial.println("Green btn hit");
  101. greenBtn();
  102. }
  103. }
  104. }
  105. Serial.println(RecordOn);
  106. }
  107. }