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.

126 lines
4.6KB

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