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.

basicTextFunctions.ino 4.5KB

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