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.

136 lines
4.7KB

  1. /*
  2. Basic Text Functions (only internal fonts)
  3. Here's an example of how to use text commands on RA8875
  4. It shows many commands and all commented so you can figure out the library ability
  5. */
  6. #include <SPI.h>
  7. #include <RA8875.h>
  8. /*
  9. Teensy3.x and Arduino's
  10. You are using 4 wire SPI here, so:
  11. MOSI: 11//(for MEGA/DUE refere to arduino site)
  12. MISO: 12//(for MEGA/DUE refere to arduino site)
  13. SCK: 13//(for MEGA/DUE refere to arduino site)
  14. the rest of pin below:
  15. */
  16. #define RA8875_CS 10 //see below...
  17. /*
  18. DUE can use: 4,10,52(o 53? not remember)
  19. */
  20. #define RA8875_RESET 9//any pin or nothing!
  21. RA8875 tft = RA8875(RA8875_CS,RA8875_RESET);
  22. void setup()
  23. {
  24. Serial.begin(38400);
  25. //long unsigned debug_start = millis ();
  26. //while (!Serial && ((millis () - debug_start) <= 5000)) ;
  27. Serial.println("RA8875 start");
  28. //initialization routine
  29. tft.begin(RA8875_800x480);//or whatever you have
  30. //following it's already by begin function but
  31. //if you like another background color....
  32. tft.fillWindow(RA8875_BLACK);//fill window black
  33. //now set a text color, background transparent
  34. tft.setTextColor(RA8875_WHITE);
  35. Serial.println(tft.getFontWidth(true));
  36. Serial.println(tft.getFontHeight(true));
  37. //use the classic print an println command
  38. tft.print("Hello World");
  39. //by default the text location is set to 0,0
  40. //now set it at 50,20 pixels and different color
  41. tft.setCursor(50, 20); //set cursor work in pixel!!!
  42. //this time we not using transparent background
  43. tft.setTextColor(RA8875_RED, RA8875_GREEN);
  44. tft.print("Hello World");
  45. //by default we using the internal font
  46. //so some manipulation it's possible
  47. tft.setFontScale(1);//font x1
  48. Serial.println(tft.getFontWidth());
  49. Serial.println(tft.getFontHeight());
  50. tft.setTextColor(RA8875_RED);
  51. tft.print("Hello World");
  52. //We can use current cursor location for some job...
  53. int16_t currentX, currentY;//we need this for store current cursor location
  54. tft.getCursor(currentX, currentY);//now we transfer to the currentX,currentY vars the location
  55. //now we have the location, lets draw a white pixel
  56. tft.drawPixel(currentX, currentY, RA8875_WHITE); //did you see the white dot?
  57. tft.setFontScale(0);//reset font scale
  58. //here's an alternative...
  59. //tft.setFontScale(0,1);xscale,yscale arbitrary x & y scaling
  60. tft.setCursor(0, 50);
  61. tft.setTextColor(RA8875_YELLOW);
  62. tft.println("ABCDEF 1 2 3 4");//this time println!
  63. tft.setFontSpacing(5);//now give 5 pix extra spacing between chars
  64. tft.println("ABCDEF 1 2 3 4");
  65. tft.setFontSpacing(0);//reset spacing
  66. //here's a useful feature of setCursor
  67. tft.setCursor(CENTER, CENTER); //this set text exact in the screen regardless his lenght and scale
  68. tft.setFontScale(1);//font x2
  69. tft.setTextGrandient(RA8875_YELLOW,RA8875_MAGENTA);
  70. tft.print("I'm in the center");
  71. //now use the autocenter feature
  72. tft.setFontScale(0);//reset font scale
  73. tft.drawRect((tft.width() / 2) - 25, (tft.height() / 2) - 100, 50, 50, RA8875_RED);//draw a box above the center
  74. tft.setTextColor(RA8875_YELLOW);
  75. //this will center the text inside the box!!!
  76. tft.setCursor((tft.width() / 2), (tft.height() / 2) - 75, true);
  77. tft.print("AB");
  78. tft.setFontScale(0);//reset font scale
  79. tft.setTextColor(RA8875_CYAN, RA8875_BLACK);
  80. tft.setCursor(50, 100);
  81. // Now play with cursor styles
  82. tft.print("Cursor Example: IBEAM");
  83. tft.showCursor(IBEAM, true); //activate cursor iBeam blinking
  84. delay(3000);
  85. tft.setCursor(50, 100);
  86. tft.print("Cursor Example: UNDER");
  87. tft.showCursor(UNDER, true); //activate cursor iBeam blinking
  88. delay(3000);
  89. tft.setCursor(50, 100);
  90. tft.print("Cursor Example: BLOCK");
  91. tft.showCursor(BLOCK, true); //activate cursor iBeam blinking
  92. delay(3000);
  93. tft.setCursor(50, 100);
  94. tft.print(" ");
  95. tft.showCursor(NOCURSOR, false); //deactivate cursor
  96. delay(1000);
  97. tft.setFontScale(0, 3); //font x0,x4
  98. tft.setTextColor(RA8875_CYAN, RA8875_BLACK);
  99. //here's another unusual command, setFontAdvance enable/disable font advance
  100. //so you don't have to use setCursor a lot when you need to update numbers on screen
  101. tft.cursorIncrement(false);//turn off autoAdvance
  102. tft.setCursor(100, 100);
  103. for (uint8_t i = 0; i < 10; i++) {
  104. tft.print(i, DEC);
  105. delay(200);
  106. }
  107. tft.print(" ");
  108. tft.cursorIncrement(true);//back to normal
  109. tft.setFontScale(2);//font x3
  110. tft.setTextColor(RA8875_BLUE, RA8875_BLACK);
  111. }
  112. unsigned long i = 0;
  113. void loop()
  114. {
  115. tft.setCursor(50, 100);
  116. if (i > 999) {
  117. tft.setTextColor(RA8875_CYAN, RA8875_BLACK);
  118. }
  119. if (i > 9999) {
  120. tft.setTextColor(RA8875_MAGENTA, RA8875_BLACK);
  121. }
  122. if (i > 99999) {
  123. tft.setTextColor(RA8875_RED, RA8875_BLACK);
  124. }
  125. if (i > 999999) i = 0;
  126. tft.print(i, DEC);
  127. delay(1);
  128. i++;
  129. }