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.

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