Page 1 of 1

Countdown in the center of DMD

Posted: Sat May 07, 2016 7:33 pm
by Abder_sama
Hello everybody, hope you all fine!

I'm a new member and also a beginner in programming DMD with Arduino, so i hope learn few thing from you guys :)
I'm actually working on a project : DMD all the LEDs ON showing a countdown in the center with Arduino Uno, so as i said i already learn a lot about Arduino and i test the scrolling text it's working fine, i'm really thankful to you that your codes and explanation helps me to know more about scrolling text, now i faced a problem: what kind of code should i add to have a countdown in the middle of P10 LED (60-->0 or inverse)?

Thanks in advance.

Re: Countdown in the center of DMD

Posted: Sat May 07, 2016 9:34 pm
by stryker
Hi Abder

Presuming your biggest challenge here is the centred text, if you're using the DMD2 library, there's a function stringWidth() which will give you the number of pixels wide a character string will need in the font that's currently active (or you can specify a font as the second parameter if you prefer). Here's the definition:

Code: Select all

unsigned int stringWidth(const __FlashStringHelper *flashStr, const uint8_t *font = NULL)
Therefore if you have your countdown value converted to a string you can see how wide it will be on the DMD and use that to work out where to display it. Here's a simple function I use to display strings centred on an array of DMDs that is 2 panels wide (ie max pixel number 31).

Code: Select all

// ---------------------------------------------------------------------------------
// display thisWord, centred on the 2x2 DMD array
void displayDMDstring(char * thisWord) {
  int Xstart = 31 - (dmd.stringWidth(thisWord) / 2);                  // work out where to display the first character
  if (0 > Xstart) Xstart = 0;
  dmd.drawString(Xstart, 0, thisWord);
Aside from this you'll need to add the counter logic, and have it invert the colours on the display which is straightforward.

All the best with your project - cheers!

Re: Countdown in the center of DMD

Posted: Tue Dec 18, 2018 10:45 am
by alvinchrist
I have a question.. dmd.stringWidth() is for centering the display horizontally, how to center the display vertically? I'm currently working on 2 P10 Dot matrix display (32x32)

Re: Countdown in the center of DMD

Posted: Wed Dec 19, 2018 10:59 am
by Brissieboy
Not very familiar with the DMD2 library, but doesn't the TextBox allow you set the vertical position? Would that work for you?
You can then read the height of the font and the display then work out where to place the text box.