Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h> // Hardware-specific library
- #include <MCUFRIEND_kbv.h>
- MCUFRIEND_kbv tft;
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- String a = "";
- unsigned int lastStringLength = a.length();
- // work in line numbers. Font height in ht
- int16_t ht = 8, top = 1, line, lines = 38, scroll;
- void setup()
- {
- Serial.begin(115200);
- tft.reset();
- uint16_t id = tft.readID();
- tft.begin(id);
- tft.setRotation(2);
- tft.fillScreen(BLACK);
- tft.setTextColor(YELLOW, BLACK);
- tft.setTextSize(1); // System font is 8 pixels. ht = 8*2=16
- tft.setCursor(60, 0);
- tft.print("*** Serial-Console ***");
- //tft.println(id, HEX);
- tft.setCursor(0, 0);
- //for (line = 1; line < 41; line++) tft.println(String(line) + ": ");
- }
- void loop()
- {
- while (Serial.available()) {
- a = Serial.readString(); // read the incoming data as string
- int len = a.length();
- Serial.println(String(len));
- if (len >= 520) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll) * ht);
- Serial.println(a);
- tft.println("Line too long: " + String(len));
- }
- if (len >= 480) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+13) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 440) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+12) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 400) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+11) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 360) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+10) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 320) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+9) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 280) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+8) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 240) { // check lines for word wrap
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+7) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 200) {
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+6) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 160) {
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+5) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 120) {
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+4) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len >= 80 ) {
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+3) * ht);
- Serial.println(a);
- tft.println(a);
- }
- else if (len > 39) {
- tft.setCursor(0, ((scroll) + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll+2) * ht);
- Serial.println("len: > 40");
- Serial.println(a);
- tft.println(a);
- tft.println(" ");
- }
- else if (len < 40) {
- tft.setCursor(0, (scroll + top) * ht);
- if (++scroll >= lines) scroll = 0;
- tft.vertScroll(top * ht, lines * ht, (scroll) * ht);
- Serial.println(a);
- tft.println(a);
- }
- //delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement