lyriarte / StripDisplay

Display text and bitmaps on strip led panels.
BSD 2-Clause "Simplified" License
5 stars 0 forks source link

I can't align to the center on a 16x16 matrix #2

Closed Boaztheostrich closed 2 years ago

Boaztheostrich commented 2 years ago

Here is my code.

"#define FONT_6x9_FIXED_MEDIUM

include

XBMFont * fontP = &fixedMedium_6x9;

define STRIPLED_GPIO 5

define STRIPLED_W 16

define STRIPLED_H 16

CRGB leds[STRIPLED_W*STRIPLED_H];

StripDisplay strip(STRIPLED_GPIO, STRIPLED_W, STRIPLED_H, WRAP_COLUMNS, ORIGIN_TOP_LEFT, leds);

void setup() { FastLED.addLeds<NEOPIXEL,STRIPLED_GPIO>(leds, STRIPLED_WSTRIPLED_H); strip.setup(fontP); Serial.begin(9600); Serial.println(String(STRIPLED_WSTRIPLED_H) + String(" leds on gpio ") + String(strip.getGpio())); FastLED.setBrightness(64); }

void loop() { strip.setFgColor(CRGB::White); strip.setBgColor(CRGB::Blue); strip.setAlignment(ALIGN_CENTER); strip.setText("MSU MAKERSPACE"); for (int offset=0; offset<strip.getTextWidth(); offset++) { strip.displayText(offset); FastLED.delay(100); } }"

lyriarte commented 2 years ago

I assume you want vertical alignment here ? Because ALIGN_CENTER is for horizontal alignment and only makes sense if your rendered text is smaller than your panel width. Since you are scrolling the text I guess that's not your issue here.

For vertical alignment you can use the setLine API to define the top line of your text in your panel, which is 0 by default so text is displayed on top.

Boaztheostrich commented 2 years ago

Ah I see that would hopefully fix my issue I will try to try it monday at the latest and get back to you. Thanks for the response. I just want the text centered like it is on that video you posted to reddit except with only one matrix.

Boaztheostrich commented 2 years ago

I'm confused on how to edit the number

lyriarte commented 2 years ago

For vertical centering ? You are using a 6x9 font on a 16x16 panel, so your text is 9 lines tall and you have 16 lines on your panel. By default your text top line is line 0, but you can set it to 3 to have 3 empty lines at the top. For instance: strip.setLine(3); before the for loop, along with your other color and alignment settings.

lyriarte commented 2 years ago

Another thing regarding horizontal centering this time. Using ALIGN_CENTER is pointless when your text is larger than the panel, which is the case for your "MSU MAKERSPACE" string with 6x9 font on your 16x16 panel.

Now you probably want to start scrolling your text a few columns right of the left edge of the panel to have time to read it, like I did for the reddit post. What you need to do is start scrolling with a negative offset like in the MessageBoard example. Check how the displayMessageText function works.

Boaztheostrich commented 2 years ago

Gotcha, the tip with the offset fixed my vertical centering problem, is there anyway to change the background / foreground color while text is scrolling?

Boaztheostrich commented 2 years ago

Here is my current code but it only works when the text finishes scrolling.

define FONT_6x9_FIXED_MEDIUM

include

XBMFont * fontP = &fixedMedium_6x9;

define STRIPLED_GPIO 2

define STRIPLED_W 16

define STRIPLED_H 16

CRGB leds[STRIPLED_W*STRIPLED_H];

StripDisplay strip(STRIPLED_GPIO, STRIPLED_W, STRIPLED_H, WRAP_COLUMNS, ORIGIN_TOP_RIGHT, leds);

void setup() { FastLED.setBrightness(255); FastLED.addLeds<NEOPIXEL,STRIPLED_GPIO>(leds, STRIPLED_WSTRIPLED_H); strip.setup(fontP); Serial.begin(9600); Serial.println(String(STRIPLED_WSTRIPLED_H) + String(" leds on gpio ") + String(strip.getGpio())); pinMode(A0, INPUT); }

void loop() { strip.setAlignment(ALIGN_LEFT); int value = analogRead(A0); Serial.println(value); delay(100); strip.setLine(3); strip.setText(" MSU MAKERSPACE"); for (int offset=0; offset<strip.getTextWidth(); offset++) { strip.displayText(offset); strip.setFgColor(CRGB(value,0,0)); strip.setBgColor(CRGB::Black); FastLED.show(); FastLED.delay(200); }}

Boaztheostrich commented 2 years ago

NM I figured it out thank you!