8 x 32 Scroll text color

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.
User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

8 x 32 Scroll text color

Post by smappdooda »

I have one of the https://www.adafruit.com/product/2294 and I am working on changing the text after a button is pushed. So far, so good. I got all of that. However, I cannot seem to get the color of the text to change. Here is what I THOUGHT would work.

Code: Select all

void loop() {
  buttonState = digitalRead(buttonInput);
  if (buttonState == LOW) {
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.print(F("Howdy"));
    if (--x < -36) {
      x = matrix.width();
      matrix.Color(255, 0, 0);
    }
    matrix.show();
    delay(100);
  }
  else {
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.print(F("12345"));
    if (--x < -36) {
      x = matrix.width();
      matrix.Color(0, 255, 0);
    }
    matrix.show();
    delay(100);
  }
}
However, the text in the ELSE stays red and won't turn that color. I have tried messing with the original code in the Tiletest to no avail.

Code: Select all

const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(5);
  matrix.setTextColor(colors[0]);
}

int x    = matrix.width();
int pass = 0;

void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("Test"));

  if(--x < -30
  ) {
    x = matrix.width();

    if(++pass >= 8) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(30);
}
I know that "matrix.setTextColor(colors[0]);" sets the default starting color but need a way to override that. Deleting it just defaults all colors to white. Any help would be appreciated.

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

matrix.setTextColor() is what you should use. The function matrix.Color() does not actually set a color, it's a utility function for converting from (r,g,b) values to 32 bit color values.

Try something like this in your first code example:

Code: Select all

matrix.setTextColor(0x07FF);    // cyan
Colors values are discussed here:
https://learn.adafruit.com/adafruit-gfx ... -and-units

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

adafruit_support_carter wrote:matrix.setTextColor() is what you should use. The function matrix.Color() does not actually set a color, it's a utility function for converting from (r,g,b) values to 32 bit color values.

Try something like this in your first code example:

Code: Select all

matrix.setTextColor(0x0x07FF);    // cyan
Colors values are discussed here:
https://learn.adafruit.com/adafruit-gfx ... -and-units
When I try it that way I get the error code - "unable to find numeric literal operator 'operator""x07FF'".

I had previously tried it with "matrix.setTextColor(0, 0, 255);" but I get - "no matching function for call to 'Adafruit_NeoMatrix::setTextColor(int, int, int)'" (Which I find strange as it works fine in the other code when referencing the colors array)

EDIT: I also tried "matrix.setTextColor(colors[1]);" but it will start with the first color (red) on the first scroll and THEN stay Green. If I remove "matrix.setTextColor(colors[0]);" in setup it makes the first scroll color white. I am using an Arduino leonardo. Does this code not like those perchance?

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

OOOOPS. My bad. Heavy finger typo on my part. Sorry for the confusion. I've edit the post above, it should have been:

Code: Select all

matrix.setTextColor(0x07FF);    // cyan
You could also try something like this, if you want to use RGB triplets:

Code: Select all

matrix.setTextColor(matrix.Color(255,0,0));
But I'm seeing a mismatch between what .setTextColor() wants and what .Color() returns. So the colors may not be as expected - let me know if you see that. Like if you don't see red for the above example.

For when you are trying to use the colors array variable, note that it only has 3 entries. So this part of your code:

Code: Select all

    if(++pass >= 8) pass = 0;
    matrix.setTextColor(colors[pass]);
will have issues when pass is >= 3.

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

That works much better thanks.

For when you are trying to use the colors array variable, note that it only has 3 entries. So this part of your code:

Code: Select all

    if(++pass >= 8) pass = 0;
    matrix.setTextColor(colors[pass]);
will have issues when pass is >= 3.[/quote]

Yes that was a typo left in from a different code. I'm not using the array.

One other question: When I hit the button to switch the text and color, how do I get the current text to stop and reset if it's midway on the screen? (eg: A red "hello" scrolls across the screen, push a button, that vanishes/ resets, and now a blue "Goodbye" starts to scroll.) Is that possible? Currently, the text just switches mid scroll and stays the same color until the loop resets.

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

The scrolling is achieved by using the setCursor() function with a variable that is incremented to cause the scroll:

Code: Select all

    matrix.setCursor(x, 0);
So you just need to reset x to whatever its initial value is to effectively restart the scroll.

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

well so far I can get it to reset by putting x = matrix.width(); in my if statement but it won't scroll after that. (My programming skills are not strong)

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

You're probably resetting it constantly. Keep looking at how your logic works and think about what you want to do when the button is pressed. Currently what you have is "do this if button is down, otherwise do this". But if you want to do "change to this when button is pressed", you'll need to make your logic a little different.

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

So a state change instead of if/else. Hmmm...

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

Yep. That's what I was thinking. And reset x (and text, color, etc) on the state change.

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

Easier said than done for me. My brain can only wrap around this stuff so far. It is no exaggeration when I tell you that while I know what is going on and how, I cannot tell you why and my brain just does not get it. (Numbers are my arch-nemesis). I might have to phone a friend on this one. Thanks for getting me this far. Will do my best to force more knowledge into my skull.

User avatar
smappdooda
 
Posts: 47
Joined: Fri Feb 14, 2014 9:14 pm

Re: 8 x 32 Scroll text color

Post by smappdooda »

So after deliberation, we decided it was better to have the text and color change mid-scroll so it's obvious something has happened immediately.

Thus, I pulled "matrix.setTextColor(matrix.Color(0, 0, 255));" out of the if statement and put it above the text call and it works.

If anyone needs to do this at any point here is my code:

Code: Select all

// Adafruit_NeoMatrix example for tiled NeoPixel matrices.  Scrolls
// 'Howdy' across three 10x8 NeoPixel grids that were created using
// NeoPixel 60 LEDs per meter flex strip.

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif

#define PIN 6
int buttonInput = 2;
int buttonState = 0;

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(40);
  matrix.setTextColor(matrix.Color(255, 0, 0)); //Red
  pinMode(buttonInput, INPUT);
  digitalWrite(buttonInput, HIGH);
}

int x = matrix.width();

void loop() {
  buttonState = digitalRead(buttonInput);
  if (buttonState == LOW) {

    matrix.clear();
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.setTextColor(matrix.Color(0, 0, 255));//Blue  
    matrix.print(F("12345"));
    if (--x < -36) {
      x = matrix.width();
    }      
    matrix.show();
    delay(100);
  }

  else {
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.setTextColor(matrix.Color(255, 0, 0)); //Red
    matrix.print(F("Hello"));
    if (--x < -36) {
      x = matrix.width();
    }
    matrix.show();
    delay(100);
  }
}

User avatar
223
 
Posts: 10
Joined: Tue May 29, 2018 10:25 pm

Re: 8 x 32 Scroll text color

Post by 223 »

hi how control muiti bitmap on the one oled lcd and one arduino my oled is sh1106 driver and my graphic library is gfx My question is, how can I control multi bitmap


if (data[0] == 20) {display.drawBitmap(20,0,bat_bmp0, 16, 7, 1);}
if (data[0] == 30) {display.drawBitmap(20,0,bat_bmp1, 16, 7, 1);}
if (data[0] == 40) {display.drawBitmap(20,0,bat_bmp2, 16, 7, 1);}
if (data[0] == 50) {display.drawBitmap(20,0,bat_bmp3, 16, 7, 1);}
if (data[0] == 60) {display.drawBitmap(20,0,bat_bmp4, 16, 7, 1);}
if (data[0] == 70) {display.drawBitmap(20,0,bat_bmp5, 16, 7, 1);}
if (data[0] == 80) {display.drawBitmap(20,0,bat_bmp6, 16, 7, 1);}
if (data[0] == 90) {display.drawBitmap(20,0,bat_bmp7, 16, 7, 1);}
if (data[0] == 100) {display.drawBitmap(20,0,bat_bmp8, 16, 7, 1);}
if (data[0] == 110) {display.drawBitmap(20,0,bat_bmp9, 16, 7, 1);}
if (data[0] == 120) {display.drawBitmap(20,0,bat_bmp10, 16, 7, 1);}
if (data[0] == 130) {display.drawBitmap(20,0,bat_bmp11, 16, 7, 1);}
if (data[0] == 140) {display.drawBitmap(20,0,bat_bmp12, 16, 7, 1);}
if (data[0] == 150) {display.drawBitmap(20,0,bat_bmp13, 16, 7, 1);}
batt 1 andicator


if (data[0] == 220) {display.drawBitmap(40,0,bat_bmp0, 16, 7, 1);}
if (data[0] == 230) {display.drawBitmap(40,0,bat_bmp1, 16, 7, 1);}
if (data[0] == 240) {display.drawBitmap(40,0,bat_bmp2, 16, 7, 1);}
if (data[0] == 250) {display.drawBitmap(40,0,bat_bmp3, 16, 7, 1);}
if (data[0] == 260) {display.drawBitmap(40,0,bat_bmp4, 16, 7, 1);}
if (data[0] == 270) {display.drawBitmap(40,0,bat_bmp5, 16, 7, 1);}
if (data[0] == 280) {display.drawBitmap(40,0,bat_bmp6, 16, 7, 1);}
if (data[0] == 290) {display.drawBitmap(40,0,bat_bmp7, 16, 7, 1);}
if (data[0] == 300) {display.drawBitmap(40,0,bat_bmp8, 16, 7, 1);}
if (data[0] == 310) {display.drawBitmap(40,0,bat_bmp9, 16, 7, 1);}
if (data[0] == 320) {display.drawBitmap(40,0,bat_bmp10, 16, 7, 1);}
if (data[0] == 330) {display.drawBitmap(40,0,bat_bmp11, 16, 7, 1);}
if (data[0] == 340) {display.drawBitmap(40,0,bat_bmp12, 16, 7, 1);}
if (data[0] == 350) {display.drawBitmap(40,0,bat_bmp13, 16, 7, 1);}
} batt 2 andicator

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: 8 x 32 Scroll text color

Post by adafruit_support_carter »

@223 Please start a new thread for your question.

User avatar
223
 
Posts: 10
Joined: Tue May 29, 2018 10:25 pm

Re: 8 x 32 Scroll text color

Post by 223 »

HOW CONTROL MULTI BITMAPS IN THE ONE OLED LCD AND ARDUINO

how edited library oled sh1106 for high speed drawing for drawing multi bitmap

Sorry my english Language

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

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