Vertical Scrolling, don't know where to start
by bridge2nowhere on Fri May 22, 2020 9:52 am
I want to vertically scroll half the screen (on an Sharp Memory Display LCD). The text is stored in a char* which is variable length, I just gave a sample of what we're working with. I have no idea where to start with this, is there a good way to count "\n" and start in the middle of the string?
- Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <RotaryEncoder.h>
#include <Adafruit_SharpMem.h>
#include <SPI.h>
//#include <StreamUtils.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();
//keep this part static
display.println("line 1");
display.println("line 2");
display.println("line 3");
//scroll this part using an encoder
display.println(*mending);
display.refresh();
}