PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

133 行
3.3KB

  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 <ILI9488_t3.h>
  9. #include <TouchScreen.h>
  10. //Touchscreen X+ X- Y+ Y- pins
  11. #define YP A3 // must be an analog pin, use "An" notation!
  12. #define XM A2 // must be an analog pin, use "An" notation!
  13. #define YM 5 // can be a digital pin
  14. #define XP 4 // can be a digital pin
  15. // This is calibration data for the raw touch data to the screen coordinates
  16. #define TS_MINX 150
  17. #define TS_MINY 120
  18. #define TS_MAXX 920
  19. #define TS_MAXY 940
  20. #define MINPRESSURE 10
  21. #define MAXPRESSURE 1000
  22. // For better pressure precision, we need to know the resistance
  23. // between X+ and X- Use any multimeter to read it
  24. // For the one we're using, its 300 ohms across the X plate
  25. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  26. #define TFT_CS 10
  27. #define TFT_DC 9
  28. ILI9488_t3 tft = ILI9488_t3(&SPI, TFT_CS, TFT_DC);
  29. boolean RecordOn = false;
  30. #define FRAME_X 210
  31. #define FRAME_Y 180
  32. #define FRAME_W 100
  33. #define FRAME_H 50
  34. #define REDBUTTON_X FRAME_X
  35. #define REDBUTTON_Y FRAME_Y
  36. #define REDBUTTON_W (FRAME_W/2)
  37. #define REDBUTTON_H FRAME_H
  38. #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
  39. #define GREENBUTTON_Y FRAME_Y
  40. #define GREENBUTTON_W (FRAME_W/2)
  41. #define GREENBUTTON_H FRAME_H
  42. void drawFrame()
  43. {
  44. tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9488_BLACK);
  45. }
  46. void redBtn()
  47. {
  48. tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9488_RED);
  49. tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9488_BLUE);
  50. drawFrame();
  51. tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
  52. tft.setTextColor(ILI9488_WHITE);
  53. tft.setTextSize(2);
  54. tft.println("ON");
  55. RecordOn = false;
  56. }
  57. void greenBtn()
  58. {
  59. tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9488_GREEN);
  60. tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9488_BLUE);
  61. drawFrame();
  62. tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
  63. tft.setTextColor(ILI9488_WHITE);
  64. tft.setTextSize(2);
  65. tft.println("OFF");
  66. RecordOn = true;
  67. }
  68. void setup(void)
  69. {
  70. Serial.begin(9600);
  71. tft.begin();
  72. tft.fillScreen(ILI9488_BLUE);
  73. // origin = left,top landscape (USB left upper)
  74. tft.setRotation(1);
  75. redBtn();
  76. }
  77. void loop()
  78. {
  79. // Retrieve a point
  80. TSPoint p = ts.getPoint();
  81. // See if there's any touch data for us
  82. if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  83. {
  84. // Scale using the calibration #'s
  85. // and rotate coordinate system
  86. p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
  87. p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
  88. int y = tft.height() - p.x;
  89. int x = p.y;
  90. if (RecordOn)
  91. {
  92. if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
  93. if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
  94. Serial.println("Red btn hit");
  95. redBtn();
  96. }
  97. }
  98. }
  99. else //Record is off (RecordOn == false)
  100. {
  101. if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
  102. if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
  103. Serial.println("Green btn hit");
  104. greenBtn();
  105. }
  106. }
  107. }
  108. Serial.println(RecordOn);
  109. }
  110. }