Sample code: Horizontal Scrolling of a text string

This was the “Hello world” sketch that I wrote to start playing with MicroView. I tweeted a short youtube video https://www.youtube.com/watch?v=vpmuiTHIEOA and somebody asked for the code. I do not even know if text scrolling is supported “natively” by the MicroView library. Just in case it is useful for someone else, I have decided to post the code here.

#include <MicroView.h>
// MicroView scrolling sketch
// Written by @tumaku_ 2014 

int mStartPosition=63;
int mCharWidth=0;
uint8_t mString [] ={'H','o','l','a',' ','m','u','n','d','o','!','!','!'};
int mStringSize=13;
void setup() {
	uView.begin();				// start MicroView
	uView.clear(PAGE);			// clear page
        uView.setFontType(1);
        mCharWidth=uView.getFontWidth();
        delay(1000);
}

void loop () {
	uView.clear(PAGE);
        for (int j=0; j<mStringSize; j++){
          drawChar(mStartPosition+mCharWidth*j,18,mString[j]);
        }
        mStartPosition--;
        uView.display();
        delay(20);
        if (mStartPosition<-mStringSize*mCharWidth) mStartPosition=63;
}

void drawChar(int x, int y, uint8_t value) {
   if ((x+ mCharWidth>0)&&(x<64)) uView.drawChar(x,y,value);
}

tumaku:
I do not even know if text scrolling is supported “natively” by the MicroView library.

There are functions to do left and right scrolling in hardware, **uView.scrollLeft** and **uView.scrollRight**, but they are very limited.
  • - The area you want to scroll must be on the screen.
  • - The scroll region is limited to a single area starting and ending on 8 pixel high boundaries (pages), and will be the full width.
  • - The scroll region will be padded with a blank area the width of the screen.
  • - You can't control the speed (although this is a future possibility).
  • Unless these limitations suit your purposes, using software to scroll is required, as in the original post.

    uView.scrollLeft example:

    #include <MicroView.h>
    
    void setup() {
      uView.begin();
      uView.clear(PAGE);
      uView.print("<- Scroll");
      uView.setCursor(0, 16);
      uView.print("Hola");
      uView.setCursor(0, 24);
      uView.print("mundo!!!");
      uView.display();
      delay(3000);
      // scroll region is page 2 to page 3
      // (vertical pixels 16 to 31)
      uView.scrollLeft(2, 3);
    }
    
    void loop() {
    }