OLED scrolling setTextWrap(false) doesn't behave as expected

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jakeschievink
 
Posts: 4
Joined: Wed Jan 22, 2014 10:48 pm

OLED scrolling setTextWrap(false) doesn't behave as expected

Post by jakeschievink »

So i want to display a long string of text, so long that it would trail off the screen. I made it so that the text stopped wrapping with display.setTextWrap(false);
however, now when I try to scroll the text none of the text, which supposedly should be somewhere off the screen to the right, is being displayed. The string cuts off at "Hello WOrrr" and then just scrolls that part of the text again and again for 10000ms

Any ideas?

Code: Select all

 display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  display.setCursor(10,20);
  display.clearDisplay();
  display.print("Hello WOrrrrrllllllllllllllllllllllllllllldddd");
  display.display();
 
  display.startscrollleft(0x00, 0x0F);
  delay(10000);

sraney
 
Posts: 6
Joined: Thu Jan 23, 2014 12:48 am

Re: OLED scrolling setTextWrap(false) doesn't behave as expe

Post by sraney »

I was about to post the same question, I've been trying to think of a way to make a scrolling marque with constant updates.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: OLED scrolling setTextWrap(false) doesn't behave as expe

Post by adafruit_support_bill »

Which OLED display are you referringt to? We have many different kinds and they all have different capabilities.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: OLED scrolling setTextWrap(false) doesn't behave as expe

Post by pburgess »

The OLED scroll functions aren't quite as snazzy as one might expect; they just rotate the contents of the frame buffer, there's no larger "playfield" to move about.

Instead, it's necessary to re-draw each frame, keeping track of the text X position and moving it left each time. Like this:

Code: Select all

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

#define OLED_DC    11
#define OLED_CS    12
#define OLED_CLK   10
#define OLED_MOSI   9
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

char message[] = "Hello WOrrrrrllllllllllllllllllllllllllllldddd";
int  x, minX;

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  x    = display.width();
  minX = -12 * strlen(message); // 12 = 6 pixels/character * text size 2
}

void loop() {
  display.clearDisplay();
  display.setCursor(x, 20);
  display.print(message);
  display.display();

  if(--x < minX) x = display.width();
}

jakeschievink
 
Posts: 4
Joined: Wed Jan 22, 2014 10:48 pm

Re: OLED scrolling setTextWrap(false) doesn't behave as expe

Post by jakeschievink »

Thank you, that works great. I was about to write something like that, but I hesitated because I though the functionality was in function provided by the library. Have a great day :]

User avatar
xyzmaker
 
Posts: 58
Joined: Fri Jan 26, 2018 7:09 pm

Re: OLED scrolling setTextWrap(false) doesn't behave as expe

Post by xyzmaker »

Hello- I was happy to find some example code for scrolling and I quickly converted it to use the SSD_1351 library since I am using a 1.5" OLED. I also make the "x" variables work on the y-axis enabling vertical scrolling. I want the code to display a series of lines at once, but to my frustration changing the variables didn't change the amount the string scrolled up, it just stayed at 1 pixel. Do you know how I can modify the code so it changes the amount it moves up the screen each refresh?


Thanks

Here's my code.

Code: Select all

// Screen dimensions
#define SCREEN_WIDTH  128
#define SCREEN_HEIGHT 128 // Change this to 96 for 1.27" OLED.

// You can use any (4 or) 5 pins 
#define SCLK_PIN 11
#define MOSI_PIN 12
#define DC_PIN   10
#define CS_PIN   8
#define RST_PIN  9

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define ARDUBLUE        0x00CC
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <SPI.h>

// Option 1: use any pins but a little slower
Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, CS_PIN, DC_PIN, MOSI_PIN, SCLK_PIN, RST_PIN);  

// Option 2: must use the hardware SPI pins 
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be 
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
//Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, RST_PIN);

float p = 3.1415926;

//---------------------------------------------------------------------------------------------------------------------------

char message[] = "Hello WOrrrrrllllllllllllllllllllllllllllldddd";
int  y, minY;

void setup() {
  tft.begin();
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.setTextWrap(false);
  y    = tft.height()+10;// so it starts out at the point on the screen, not below
  minY = -12 * strlen(message); // 12 = 6 pixels/character * text size 2
}

void loop() {
  delay(1000);
  tft.fillScreen(BLACK);
  tft.setCursor(0, y);
  tft.print(message);

  if(--y< minY) y = tft.height();
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”