Go Down

### Topic: [SOLVED] Q: GLCD print - Display 5 digits (Read 922 times)previous topic - next topic

#### Foolios

##### Aug 02, 2012, 12:45 amLast Edit: Aug 02, 2012, 03:04 am by Foolios Reason: 1
In the doc I find:
Code: [Select]
`Serial.println(1.23456, 4)` gives "1.2346"

I want to try to hold 5 digits, Ex. 00025

So for glcd I wrote:
Code: [Select]
`GLCD.print(millis()/10000,5);` 'hoping that the ,5 would hold 5 places in an attempt to get close.

Is it possible? Or is the placeholder only going to work for decimal values, ie. 0.12000 ?

#### WizenedEE

#1
##### Aug 02, 2012, 01:43 am
There is currently a thread on the first page of this forum discussing the exact same thing.

#### Foolios

#2
##### Aug 02, 2012, 02:19 amLast Edit: Aug 02, 2012, 02:41 am by Foolios Reason: 1
I see this one:
http://arduino.cc/forum/index.php/topic,116861.0.html

I will try to incorporate it.

Maybe inside a loop:
EDIT:

Code: [Select]
`int digits = millis()/10000;int digchk = digits;switch (digchk) {    case 5: { if (digchk<10000) { GLCD.print('0'); }}    case 4: { if (digchk<1000)  { GLCD.print('00'); }}    case 3: { if (digchk<100)   { GLCD.print('000'); }}    case 2: { if (digchk<10)    { GLCD.print('0000'); }}}GLCD.print(digits);//digchk = 0;`

EDIT: Got it.

Code: [Select]
`void loop() {  // set the cursor to column 0, line 1  // (note: line 1 is the second row, since counting begins with 0):  GLCD.CursorTo(0, 1);  // print the number of seconds since reset:  int digits = millis()/10000;  int digchk = digits;  switch (digchk) {    case 5: { if (digchk<10000) { GLCD.print('0'); }}    case 4: { if (digchk<1000)  { GLCD.print('00'); }}    case 3: { if (digchk<100)   { GLCD.print('000'); }}    case 2: { if (digchk<10)    { GLCD.print('0000'); }}  }  GLCD.print(digits);}`

I don't get what this means:
Code: [Select]
`// set the cursor to column 0, line 1  // (note: line 1 is the second row, since counting begins with 0):  GLCD.CursorTo(0, 1);`

There isn't a cursor on the screen. Can someone explain?
EDIT: ah ok, the second row on the screen is where text will start...

#### bperrybap

#3
##### Aug 02, 2012, 03:14 amLast Edit: Aug 02, 2012, 03:16 am by bperrybap Reason: 1
Well, I guess the terminology used in glcd may be a bit confusing.
While there is no visible cursor shown on the glcd display, there is a cursor position.
The next printed character on the glcd in the text area will be at the current
cursor position for the text area (each text area has its own "cursor" position).

Does that make sense?
You can think of glcd as having an "invisible" cursor.

One thing to take note of is that if you intend to overwrite the numbers with a new
set of numbers, you must to use a fixed width font. Otherwise even though there may
be the same number of digits printing, the overall width in pixels of all the digits
may not be the same. This is because with most proportional fonts, the digits are not
all the same width in pixels.

BTW, the glcd library supports xxprintf() formatting so if you want you can use
GLCD.Printf() to format your output strings. It will cost you about 1.5-1.8k of flash space
but it makes formatting really easy and is very easy to update/modify the formating.

i.e.

Code: [Select]
`GLCD.Printf("%05d", millis()/1000); // print number of seconds since reset as 5 zero filled digitsGLCD.Printf("%5d", millis()/1000); // print number of seconds since reset as 5 right adjusted digits`
should do what you wanted in your example.

See the BigNums example for other Printf examples and some examples of how
to use glcd text areas.

--- bill

#### Foolios

#4
##### Aug 02, 2012, 10:50 pmLast Edit: Aug 03, 2012, 12:03 am by Foolios Reason: 1
Thank you for the instruction, advice, and example. I will look at them and post back. Big text. Ooooooooooo!!!

EDIT:
Thank you for the code. The switch statement I was using didn't do the job.

Thanks for the fix.

Go Up