2

I am trying to set the text to scroll vertically. I have a big chunk of text (example in the code below) to be set to scroll vertically. What I want is to display the complete text on the screen. Presently it scrolls the complete chunk of text. Any help or guidance is heartily welcome.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Sometimes we dont want to scroll entire display. ");
  display.startscrollright(0x00, 0x0F);

  
  
  display.display();

  delay(1000);
}
void loop(){

}

The link to the project is here: https://wokwi.com/arduino/projects/302023407584674313

3rd edit

My question:

My goal is to display the text in the window. The text should not go out of the window. If the text is too long, it should scroll vertically.

Thanks again, everyone.

8
  • 3
    I'm not 100% sure what you're asking; your text mentions vertical scrolling, your code does horizontal scrolling of 16 rows, and your text presumably is much wider than the screen. Can you edit the question to be more clear? Jun 21, 2021 at 16:00
  • So you don't want to scroll, you want to wrap the text? Jun 22, 2021 at 14:54
  • So... you've abandoned the question about scrolling and instead want to just render some text as large as possible on the screen?
    – timemage
    Jun 22, 2021 at 23:59
  • @DaveNewton timemage The whole text should be fit in the screen., It need not become large., It has to be scrollable, when the test is more than what the device can display
    – Ram Kumar
    Jun 23, 2021 at 17:56
  • 1
    okay. I will update the question clearly soon
    – Ram Kumar
    Jun 23, 2021 at 18:11

1 Answer 1

1

This line achieved it for me. I stole it from here: Adafruit Forum

display.startscrolldiagright(0x0F, 0x0F);

It sets diagonal scroll, but start and stop positions are multiples of the display width so that in total, it scrolls vertically up.

Alternatively, you edit the display buffer; by removing your content from the current position, deleting the first line of pixels, adding a new last line of pixels, writing it all back to the display buffer and then call display.display().

This is not exactly saving your microcontroller time but it works, too. I asked ChatGpt to do the coding for the second solution, it delivered. I won't post the code here though, as it is against the rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.