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.

CapTouchPaint.ino 4.3KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /***************************************************
  2. This is our touchscreen painting example for the Adafruit ILI9341
  3. captouch shield
  4. ----> http://www.adafruit.com/products/1947
  5. Check out the links above for our tutorials and wiring diagrams
  6. Adafruit invests time and resources providing this open source code,
  7. please support Adafruit and open-source hardware by purchasing
  8. products from Adafruit!
  9. Written by Limor Fried/Ladyada for Adafruit Industries.
  10. MIT license, all text above must be included in any redistribution
  11. ****************************************************/
  12. #include <SPI.h> // this is needed for display
  13. #include <ILI9488_t3.h>
  14. #include <Wire.h> // this is needed for FT6206
  15. #include <Adafruit_FT6206.h>
  16. // The FT6206 uses hardware I2C (SCL/SDA)
  17. Adafruit_FT6206 ctp = Adafruit_FT6206();
  18. // The display also uses hardware SPI, plus #9 & #10
  19. #define TFT_RST 8
  20. #define TFT_DC 9
  21. #define TFT_CS 10
  22. #define TFT_BL 7
  23. ILI9488_t3 tft = ILI9488_t3(&SPI, TFT_CS, TFT_DC, TFT_RST);
  24. // Size of the color selection boxes and the paintbrush size
  25. #define BOXSIZE 40
  26. #define PENRADIUS 3
  27. int oldcolor, currentcolor;
  28. void setup(void) {
  29. while (!Serial); // used for leonardo debugging
  30. Serial.begin(115200);
  31. Serial.println(F("Cap Touch Paint!"));
  32. tft.begin();
  33. if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
  34. Serial.println("Couldn't start FT6206 touchscreen controller");
  35. while (1);
  36. }
  37. Serial.println("Capacitive touchscreen started");
  38. tft.fillScreen(ILI9488_BLACK);
  39. // make the color selection boxes
  40. tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9488_RED);
  41. tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9488_YELLOW);
  42. tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9488_GREEN);
  43. tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9488_CYAN);
  44. tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9488_BLUE);
  45. tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9488_MAGENTA);
  46. // select the current color 'red'
  47. tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  48. currentcolor = ILI9488_RED;
  49. }
  50. void loop() {
  51. // Wait for a touch
  52. if (! ctp.touched()) {
  53. return;
  54. }
  55. // Retrieve a point
  56. TS_Point p = ctp.getPoint();
  57. // Print out raw data from screen touch controller
  58. /*
  59. Serial.print("X = "); Serial.print(p.x);
  60. Serial.print("\tY = "); Serial.print(p.y);
  61. Serial.print(" -> ");
  62. // Maybe flip it around to match the screen.
  63. // p.x = map(p.x, 0, 240, 240, 0);
  64. // p.y = map(p.y, 0, 320, 320, 0);
  65. // Print out the remapped (rotated) coordinates
  66. Serial.print("("); Serial.print(p.x);
  67. Serial.print(", "); Serial.print(p.y);
  68. Serial.println(")");
  69. */
  70. if (p.y < BOXSIZE) {
  71. oldcolor = currentcolor;
  72. if (p.x < BOXSIZE) {
  73. currentcolor = ILI9488_RED;
  74. tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  75. } else if (p.x < BOXSIZE*2) {
  76. currentcolor = ILI9488_YELLOW;
  77. tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  78. } else if (p.x < BOXSIZE*3) {
  79. currentcolor = ILI9488_GREEN;
  80. tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  81. } else if (p.x < BOXSIZE*4) {
  82. currentcolor = ILI9488_CYAN;
  83. tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  84. } else if (p.x < BOXSIZE*5) {
  85. currentcolor = ILI9488_BLUE;
  86. tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  87. } else if (p.x <= BOXSIZE*6) {
  88. currentcolor = ILI9488_MAGENTA;
  89. tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9488_WHITE);
  90. }
  91. if (oldcolor != currentcolor) {
  92. if (oldcolor == ILI9488_RED)
  93. tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9488_RED);
  94. if (oldcolor == ILI9488_YELLOW)
  95. tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9488_YELLOW);
  96. if (oldcolor == ILI9488_GREEN)
  97. tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9488_GREEN);
  98. if (oldcolor == ILI9488_CYAN)
  99. tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9488_CYAN);
  100. if (oldcolor == ILI9488_BLUE)
  101. tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9488_BLUE);
  102. if (oldcolor == ILI9488_MAGENTA)
  103. tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9488_MAGENTA);
  104. }
  105. }
  106. if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
  107. tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
  108. }
  109. }