Scrolling

This is a simplified version of my program, I have long text char* arrays that I would like to vertically scroll by rotating an encoder. To complicate it more, I have a couple lines of text that I want to keep static. I'm not even sure where to start on this.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <RotaryEncoder.h>
#include <Adafruit_SharpMem.h>
#include <SPI.h>
#include <Fonts/FreeSansBold12pt7b.h>


#define ENCODER_BUTT 6 //sw
#define ENCODER_1 5 //clk
#define ENCODER_2 9 //dt

#define SHARP_SCK  13
#define SHARP_MOSI 12
#define SHARP_SS   11

#define BLACK 0
#define WHITE 1


RotaryEncoder encoder(ENCODER_1, ENCODER_2);
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 400, 240);



const PROGMEM char* mending[220]= {"This spell repairs a single break\nor tear in an object. As long as the\nbreak or tear is no larger than 1\nfoot in any dimension. This spell\ncan physically repair a magic item\nor construct, but can't restore\nmagic."};

void setup() {

  pinMode(ENCODER_BUTT, INPUT_PULLUP);
  display.begin();
  display.clearDisplay();
  display.refresh();
  delay(2000);
}

void loop() {
  display.setFont(&FreeSansBold12pt7b);
  display.setRotation(2);
  display.setCursor(0,12);
  display.setTextColor(BLACK);
  
  //check encoder
  static int pos = 0;
  encoder.tick();
  int newPos = encoder.getPosition();



  //
  display.println("line 1");
  display.println("line 2");
  display.println("line 3");
  display.println(*mending);
  display.refresh();
}

If you want to scroll an area of the screen, you would manipulate the screen buffer e,g. with memmove()
Then write any new text into the space that was vacated.

This should be very simple for scrolling 8-rows at a time.

If you want to do smooth scrolling e.g. 1 pixel row at a time, you would use getPixel(), drawPixel()

David.

Would I have to use something like memchr to count the line breaks?

You would use getPixel(), drawPixel() to move pixels wherever you want.

When you study how the buffer and how the display stores these pixels, you can use tricks like getBuffer(), memmove(), memcpy()

Your display is 96x96. So if each line of text is 8 pixels high, it gives 12 lines of 16 characters (with the 7x5 system font)

Using FreeSansBold12pt7b is not practical. You will not get many letters on a line. Vertical scrolling would be painful. The memmove() trick only works for 8-pixel boundaries.

David.

My display is 400 x 240, so I have a bit more room to work with. This is where I currently am with my actual project. I guess an easier step would be to get rid of the top half of the screen text, that would open up some more real estate, but some spells are really long and I want the full text.

This sound feels dirty to do, but I could separate the spell into "pages" each one would be a separate attribute in the class each page would be a full screen of text. So this spell has one full page and three empty pages. It would just suck to setup.

I could not see what the controller was from the Adafruit_SharpMem code on GitHub.

If you are only interested in text, you simply draw what you want, where you want.

I really don't see how Adafruit_SharpMem can work with 400x240
Your screen is too big for an SRAM buffer.

You can store a lot of text in PROGMEM memory. And draw it pretty fast too.

David.

The micro is an Adafruit M0 Feather. I'm using a JSON file on an SD card to parse in the the spellbook into class objects.

This is where I am right now: GitHub - bridge2nowhere/SpellBook: Table Top Spellbook