Go Down

Topic: horizontal scrolling text on tft screen (Read 1 time) previous topic - next topic

david_prentice

You have a Uno.   There is no way that you can do any parallel processing.
I suppose that you could make these things fairly "magical" if you had an SPI controller and Arduino with DMA.

As it stands,   if you want to scroll two lines,  you must redraw line#1 dx pixels offset and then redraw line#2 with the required dx offset.    Rinse and repeat.   Both lines move.

Seriously,   your x3 System font looks horrible.   Even a monospaced FreeFont would look nicer.

I suggest that you design your screen displays with these limitations in mind.
One slowly scrolling window might be practical.    Multiple small jerking windows could work.

Personally,   I would prefer sensibly-sized messages drawn with an attractive font.   Possibly alternating.
Or you could replicate the "Doctors waiting room" matrix display.

Incidentally,   I wrote a rubout mode FreeFonts display.    It looks reasonable.

David.

padouet

Seriously,   your x3 System font looks horrible.   Even a monospaced FreeFont would look nicer.
You are right. I think so !
But before using 4x4x4 matrix led cub, people begin by blinking one led ...
Theory is when you know how it works and nothing happens.
Practice is when everything works and nobody knows why.
I gathered theory and practice: Nothing works ... and nobody knows why!

padouet

#32
Jul 17, 2017, 12:48 pm Last Edit: Jul 17, 2017, 07:24 pm by padouet Reason: add comment in sketch
what do you think about this sketch I wrote ?

Code: [Select]

// define here your display

unsigned long currentMillis;
class h_scroller
{
  unsigned long c_previousMillis;
  unsigned long c_interval;
  int c_av;
  int c_po;
  int c_ts;  
  int c_dw;
  int c_lc;
  int c_ca;
  int c_tl;
  int c_ed;
  int c_re;
  int c_su;
  int c_px;
  int c_py;
  String c_tx;
  
  public:
  h_scroller(int p_ts, int p_dw, int p_py, String p_tx, unsigned long p_interval)
  {     c_interval = p_interval;   // frequency to scroll
    c_previousMillis = c_interval;
    c_av = 0;  // advance in texte
    c_po = 0;  // position on screen
    c_su = 0;  // nb char beginning to display at the end
    c_px = 0;  // x position text
    c_py = p_py;  // y position text
    c_ts = p_ts; // text size on screen
    c_dw = p_dw; // speed to scroll  // 1 is slow and fluid
    c_lc = c_ts * 6;   // large pixel char
    c_tl = c_tx.length();   // text length
    c_ca = (tft.width() / c_lc) + 3;  // number char in line
    c_re = c_ca; // nb char remaining to display at the beginning
    c_tx = p_tx;  // text to scroll

  }
  void doit()
  {
    currentMillis = millis();
    if (currentMillis - c_previousMillis >= c_interval)
    {  c_previousMillis = currentMillis;
      tft.setTextSize(c_ts);
      tft.setTextColor(0xFFFF,0x0000);
      if(c_tl < c_ca)
      {
        for(int i = c_ca/c_tl ; i>0 ;i--)
        {
          c_tx = c_tx + c_tx;
        }
        c_tl = c_tx.length();
      }
      if( c_po >= c_lc)  //  next char to begin
      {
        c_po =  0;
        c_av = c_av < c_tl - 1 ?  c_av + 1 : 0;
      }
      c_re = c_tl - c_av >= c_ca ? c_av + c_ca + 1 : c_tl;
      c_su = c_tl - c_av >= c_ca ? 0 : 1 + c_ca - c_tl + c_av;
      tft.setTextWrap(false);
      tft.setCursor(-c_po,c_py);
      tft.print(c_tx.substring(c_av,c_re) + c_tx.substring(0,c_su));
      c_po += c_dw;
    }
  }
};

h_scroller text1(4, 1,180,"_abcdefghijklmnopqrstuvwxyz",100);
h_scroller text2(4, 1,80,"_12345",500);
h_scroller text3(4, 1,130,"+12345",5);


void setup(void)
{
 // init here your display for 320x240 screen landscape
    uint16_t ID = tft.readID();
    tft.begin(ID);
  tft.setRotation(1);
    tft.fillScreen(0xFFE0);
    tft.fillScreen(0x0000);
}

void loop(void)
{
  text1.doit();
  text2.doit();  
  text3.doit();  
}


I know it is not perfect...
On right border it is not very nice, I will work about.
I have a problem in class h_scroller with  
c_ca = (tft.width() / c_lc) + 3;  // number char in line
tft.width() is not the right value after   tft.setRotation(1); in setup.
I do not understand why.
Is the right way to deplace "c_ca = (tft.width() / c_lc) + 3;  // number char in line" from public to doit ?
Theory is when you know how it works and nothing happens.
Practice is when everything works and nobody knows why.
I gathered theory and practice: Nothing works ... and nobody knows why!

Go Up