Advertisement
WacKEDmaN

Untitled

Oct 27th, 2018
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #include <Adafruit_GFX.h> // Hardware-specific library
  2. #include <MCUFRIEND_kbv.h>
  3. MCUFRIEND_kbv tft;
  4.  
  5. #define BLACK 0x0000
  6. #define BLUE 0x001F
  7. #define RED 0xF800
  8. #define GREEN 0x07E0
  9. #define CYAN 0x07FF
  10. #define MAGENTA 0xF81F
  11. #define YELLOW 0xFFE0
  12. #define WHITE 0xFFFF
  13.  
  14. String a = "";
  15. unsigned int lastStringLength = a.length();
  16.  
  17. // work in line numbers. Font height in ht
  18. int16_t ht = 8, top = 1, line, lines = 38, scroll;
  19.  
  20. void setup()
  21. {
  22. Serial.begin(115200);
  23. tft.reset();
  24. uint16_t id = tft.readID();
  25. tft.begin(id);
  26. tft.setRotation(2);
  27. tft.fillScreen(BLACK);
  28. tft.setTextColor(YELLOW, BLACK);
  29. tft.setTextSize(1); // System font is 8 pixels. ht = 8*2=16
  30. tft.setCursor(60, 0);
  31. tft.print("*** Serial-Console ***");
  32. //tft.println(id, HEX);
  33.  
  34. tft.setCursor(0, 0);
  35. //for (line = 1; line < 41; line++) tft.println(String(line) + ": ");
  36.  
  37. }
  38.  
  39. void loop()
  40. {
  41. while (Serial.available()) {
  42. a = Serial.readString(); // read the incoming data as string
  43. int len = a.length();
  44. Serial.println(String(len));
  45. if (len >= 520) { // check lines for word wrap
  46. tft.setCursor(0, ((scroll) + top) * ht);
  47. if (++scroll >= lines) scroll = 0;
  48. tft.vertScroll(top * ht, lines * ht, (scroll) * ht);
  49. Serial.println(a);
  50. tft.println("Line too long: " + String(len));
  51. }
  52. if (len >= 480) { // check lines for word wrap
  53. tft.setCursor(0, ((scroll) + top) * ht);
  54. if (++scroll >= lines) scroll = 0;
  55. tft.vertScroll(top * ht, lines * ht, (scroll+13) * ht);
  56.  
  57. Serial.println(a);
  58. tft.println(a);
  59. }
  60. else if (len >= 440) { // check lines for word wrap
  61. tft.setCursor(0, ((scroll) + top) * ht);
  62. if (++scroll >= lines) scroll = 0;
  63. tft.vertScroll(top * ht, lines * ht, (scroll+12) * ht);
  64.  
  65. Serial.println(a);
  66. tft.println(a);
  67. }
  68. else if (len >= 400) { // check lines for word wrap
  69. tft.setCursor(0, ((scroll) + top) * ht);
  70. if (++scroll >= lines) scroll = 0;
  71. tft.vertScroll(top * ht, lines * ht, (scroll+11) * ht);
  72.  
  73. Serial.println(a);
  74. tft.println(a);
  75. }
  76. else if (len >= 360) { // check lines for word wrap
  77. tft.setCursor(0, ((scroll) + top) * ht);
  78. if (++scroll >= lines) scroll = 0;
  79. tft.vertScroll(top * ht, lines * ht, (scroll+10) * ht);
  80.  
  81. Serial.println(a);
  82. tft.println(a);
  83. }
  84. else if (len >= 320) { // check lines for word wrap
  85. tft.setCursor(0, ((scroll) + top) * ht);
  86. if (++scroll >= lines) scroll = 0;
  87. tft.vertScroll(top * ht, lines * ht, (scroll+9) * ht);
  88.  
  89. Serial.println(a);
  90. tft.println(a);
  91. }
  92. else if (len >= 280) { // check lines for word wrap
  93. tft.setCursor(0, ((scroll) + top) * ht);
  94. if (++scroll >= lines) scroll = 0;
  95. tft.vertScroll(top * ht, lines * ht, (scroll+8) * ht);
  96.  
  97. Serial.println(a);
  98. tft.println(a);
  99. }
  100. else if (len >= 240) { // check lines for word wrap
  101. tft.setCursor(0, ((scroll) + top) * ht);
  102. if (++scroll >= lines) scroll = 0;
  103. tft.vertScroll(top * ht, lines * ht, (scroll+7) * ht);
  104.  
  105. Serial.println(a);
  106. tft.println(a);
  107. }
  108. else if (len >= 200) {
  109. tft.setCursor(0, ((scroll) + top) * ht);
  110. if (++scroll >= lines) scroll = 0;
  111. tft.vertScroll(top * ht, lines * ht, (scroll+6) * ht);
  112.  
  113. Serial.println(a);
  114. tft.println(a);
  115. }
  116. else if (len >= 160) {
  117. tft.setCursor(0, ((scroll) + top) * ht);
  118. if (++scroll >= lines) scroll = 0;
  119. tft.vertScroll(top * ht, lines * ht, (scroll+5) * ht);
  120.  
  121. Serial.println(a);
  122. tft.println(a);
  123. }
  124. else if (len >= 120) {
  125. tft.setCursor(0, ((scroll) + top) * ht);
  126. if (++scroll >= lines) scroll = 0;
  127. tft.vertScroll(top * ht, lines * ht, (scroll+4) * ht);
  128.  
  129. Serial.println(a);
  130. tft.println(a);
  131. }
  132. else if (len >= 80 ) {
  133. tft.setCursor(0, ((scroll) + top) * ht);
  134. if (++scroll >= lines) scroll = 0;
  135. tft.vertScroll(top * ht, lines * ht, (scroll+3) * ht);
  136.  
  137. Serial.println(a);
  138. tft.println(a);
  139. }
  140. else if (len > 39) {
  141. tft.setCursor(0, ((scroll) + top) * ht);
  142. if (++scroll >= lines) scroll = 0;
  143. tft.vertScroll(top * ht, lines * ht, (scroll+2) * ht);
  144. Serial.println("len: > 40");
  145. Serial.println(a);
  146. tft.println(a);
  147. tft.println(" ");
  148. }
  149. else if (len < 40) {
  150. tft.setCursor(0, (scroll + top) * ht);
  151. if (++scroll >= lines) scroll = 0;
  152. tft.vertScroll(top * ht, lines * ht, (scroll) * ht);
  153.  
  154. Serial.println(a);
  155. tft.println(a);
  156. }
  157.  
  158. //delay(100);
  159.  
  160.  
  161. }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement