Author Topic: Vacuum Fluorescent Display (VFD) Alarm Clock Using LCD Font  (Read 11027 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Vacuum Fluorescent Display (VFD) Alarm Clock Using LCD Font
« on: December 03, 2020, 06:52:38 pm »
I'm sure many of you have made this already, but I never have until today. It's a LCD display of the clock and date in large 72 size Lcd.ttf font. I also made it AM/PM because I'm sure most of you don't use the 24 hour clock. lol I made it a green LCD display like one of the clocks I have. I added the Lcd.ttf file to the zip file. Just put it in the same directory as the clock. You also can use it as a Windows font in your Windows/Fonts directory but most likely this comes with Windows anyways and you already have it.

Edit: I just added code to make it an alarm clock too! :) The zip file below has been updated.
Edit: Added "8" LCD shadows, a minor Esc key fix by making fonts small again when closing program, and stopped AM/PM from moving.
Edit: Lined up 8's a bit better. minor fixes, etc. See the code's remarks for more details.
Edit: Changed font and everything lines up perfectly now.
Edit: Fixed the hour line-up using _TRIM$.
Edit: Fixed one line.
Edit: Fixed Again
Edit: Fixed 0 hour from 24 hour clock to 12. (December 5, 2020).
Time and Date VFD by SierraKen.jpg
* Time and Date VFD by SierraKen.jpg (Filesize: 38.29 KB, Dimensions: 500x227, Views: 264)
* Alarm Clock VFD - 12-5-2020 update 7.zip (Filesize: 7.17 KB, Downloads: 181)
« Last Edit: December 05, 2020, 06:17:58 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #1 on: December 03, 2020, 08:18:12 pm »
I just added code to make it an alarm clock as well. You can set it for the year, month, day, hour, minute, and second. The updated zip file is above on the first post. Here is also a photo of it. Tell me what you think, thanks.

Edit: This is a very old version of the clock, the newer version is updated on the first post of this forum thread.
Alarm Clock LCD by SierraKen.jpg
* Alarm Clock LCD by SierraKen.jpg (Filesize: 36.38 KB, Dimensions: 400x228, Views: 254)
« Last Edit: December 04, 2020, 11:32:57 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #2 on: December 03, 2020, 09:32:26 pm »
Ha! I am looking all over to see how you drew the segments to the digits... Oh, it's a Font! :0

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #3 on: December 03, 2020, 09:45:58 pm »
Yep. :D And I learned a lot about fonts with this. I made it the highest size of 72 for that certain one.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #4 on: December 03, 2020, 10:01:01 pm »
Looks good to me.  Nice font choice for it.

- Dav

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: LCD Time and Date Using Windows Font
« Reply #5 on: December 03, 2020, 10:02:11 pm »
Yep. :D And I learned a lot about fonts with this. I made it the highest size of 72 for that certain one.

Fonts have a highest size?  Since when?  Have you tried it at a higher point value?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #6 on: December 03, 2020, 11:20:51 pm »
Dang I had no idea Steve! I said "highest" because that's the highest number it uses on Microsoft Wordpad. I just threw in a size 120 on a test and it's HUGE! Thank you!!!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #7 on: December 03, 2020, 11:23:05 pm »
I'll keep this clock as size 72 though because it's a nice size that doesn't get in the way.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #8 on: December 03, 2020, 11:24:39 pm »
Thanks Dav. :) I hope people will use the alarm function. You can even set it to 10 seconds later or whatever. It continues to beep until you press any key.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #9 on: December 04, 2020, 01:53:41 am »
I just updated this clock to look better mostly and a minor fix (when you click Esc it goes to smaller fonts now to end the program). I also made it so the AM/PM doesn't move anymore. Here is the new look to it. I will update the zip file on the first post above as well. Adding background LCD "8" shadows were a bit tricky and they aren't an exact match, but they are as good as I can get it. Enjoy!

Alarm Clock LCD by SierraKen 2.jpg
* Alarm Clock LCD by SierraKen 2.jpg (Filesize: 42.03 KB, Dimensions: 402x227, Views: 230)
« Last Edit: December 04, 2020, 01:57:03 am by SierraKen »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #10 on: December 04, 2020, 02:16:59 am »
Very nice, but the digits don't always line up and the "blank" can be seen underneath.
Noticed it with the minutes and the last 2 digits of the year.  I should use that font for
the clocks in my chess - it'd be faster than plotting segments.
It works better if you plug it in.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #11 on: December 04, 2020, 02:41:13 am »
Yep Richard, because the LCD fonts aren't exactly all lined up with the number 8, it won't come out perfectly. For example, the 7 is off the most from the 8 on the font. I might look at this more but I worked on just the shadows for over an hour. Not sure if I can make it better or not. I even had to add extra spaces on strings to line up just the 10's, because of the 1. It's a puzzle for sure, because like I said, not everything lines up with 8. As for the date, I just left it that way because to me it gives off a 3D effect. :)
« Last Edit: December 04, 2020, 02:43:34 am by SierraKen »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: LCD Time and Date Using Windows Font
« Reply #12 on: December 04, 2020, 07:38:56 am »
Dang I had no idea Steve! I said "highest" because that's the highest number it uses on Microsoft Wordpad. I just threw in a size 120 on a test and it's HUGE! Thank you!!!

Here's a few tips when it comes to using fonts:

1) Fonts are really nothing more than a set of graphics that scale to whatever scale you set them.  This property of them is what had me so shocked when you said 72 was the upper limit of the font you're using.  Generally speaking, whatever size you set for the font, determines the HEIGHT, in pixels, of each character of the font.   A quick example is below:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. FOR i = 10 TO 24
  3.     f = _LOADFONT("LCD.TTF", i)
  4.     _FONT f
  5.     LOCATE i - 9

As you can see, I'm using one font, from size 10 to size 24, and my _FONTHEIGHT matches the size I set for the font.  These aren't arbitrary numbers, like the dial on a radio where 1 to 10 is something different on different speakers; it's a set size of pixel height.  Width, of course, depends on the characters inside the font.  With many fonts, unless they're monospaced, "W" is a much wider character than "i".

Also, as you can see from running the above, the _FONTWIDTH is currently 0.  This is the basic response we get when we're using a font which isn't monospaced, as there's no set standard size for each character in the font.  If you get a _FONTWIDTH of 0, you'll need to use _PRINTWIDTH with each character/string to see how many pixels wide they are, when printing them to the screen.

2) QB64 has the capability to make any font monospaced.  To do so, simply add the "MONOSPACE" style tag to your _LOADFONT, as below:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. FOR i = 10 TO 24
  3.     f = _LOADFONT("LCD.TTF", i, "monospace")
  4.     _FONT f
  5.     LOCATE i - 9
  6.  

Now with the above, our _FONTWIDTH is now 1/2 our _FONTHEIGHT (rounded down), but this ratio doesn't always hold true, so don't get a false perception of that in your head.  (Think of  _FONT 8 which comes with QB64 which is 8x8 pixels in size.)  All characters are going to be a set width, and the ratio will always be the same as the font scales in size, but that ratio between width and height varies from font to font.

3) Another "Generally speaking" rule:  Unless you're doing something odd as heck with them, your best practice is just to load the font you want at the start of a program, and then keep it in memory to use.  They only use a few MB of memory to keep them loaded and ready to use, and with today's computers which allow us GB of RAM for each program, it's just not worth the hassle (and wear on the drive) to have to open a font and then close it repeatedly.  Load it once and forget it.

4) If you can't practice the "load it once and forget it" rule, then don't forget to make use of _FREEFONT.  If you load a font and never free it, your program's memory usage will simply go up, up, and up, until it eventually uses all the resources on your machine and crashes.  These types of memory leaks become readily apparent when applied inside a loop, SUB, or FUNCTION.

5) Last tidbit of knowledge which I can think to share with you:  Each time you load a font, QB64 resets your print location to the top left corner of the screen.  For a quick example, run the following code:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. DIM f(10 TO 128)
  3. FOR i = 10 TO 128
  4.     f(i) = _LOADFONT("LCD.TTF", i, "monospace")
  5.  
  6. PRINT "Hello World (in default text)"
  7.  
  8. _FONT f(16)
  9. PRINT "Hello World (in LCD-16 text)"
  10.  
  11. _FONT f(32)
  12. PRINT "Hello World (in LCD-32 text)"
  13.  

Notice how every time you break the SLEEP, the text prints in the top left corner?  Every font change will produce this affect to your print location.  If you want to preserve your print location, add my little SafeLoadFont routine into your code and use it, as below:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. DIM f(10 TO 128)
  3. FOR i = 10 TO 128
  4.     f(i) = _LOADFONT("LCD.TTF", i, "monospace")
  5.  
  6. PRINT "Hello World (in default text)"
  7.  
  8. SafeLoadFont f(16)
  9. PRINT "Hello World (in LCD-16 text)"
  10.  
  11. SafeLoadFont f(32)
  12. PRINT "Hello World (in LCD-32 text)"
  13.  
  14.  
  15. SUB SafeLoadFont (font#)
  16.     'Safely loads a font without destroying our current print location and making it revert to the top left corner.
  17.  
  18.     down = CSRLIN: right = POS(0)
  19.     down = (down - 1) * _FONTHEIGHT
  20.     IF _FONTWIDTH <> 0 THEN 'we start with a monospace font
  21.         right = (right - 1) * _PRINTWIDTH(" ") 'convert the monospace LOC to a graphic X coordinate
  22.     END IF
  23.     _FONT font#
  24.     IF _FONTWIDTH <> 0 THEN 'we swapped to a monospace font
  25.         right = (right / _PRINTWIDTH(" ")) + 1 'convert the graphic X coordinate back to a monospace LOC column
  26.     END IF
  27.     down = (down / _FONTHEIGHT) + 1
  28.     IF right < 1 THEN right = 1
  29.     LOCATE down, right
  30.  




And that's about all the pointers/tips that I think I know to share with you, concerning the use of fonts in your programs.  if you have any questions, feel free to ask, and I'll do what I can to help answer them for you.  Honestly, there's nothing too complex about adding them into a program, and making them work. 

Usually the biggest problem comes with folks saying, "Font not found", and the best way to get around that is to make the font available for download with the program just like you would any other resource.  Just don't assume that it comes with someone's OS by default, cause every OS seems to have a different set that they package with it.   Old English font (OLDENGL.ttf) is one I like the looks of, and use a lot, and it  comes with WIN XP, but not Vista, but it's in WIN 7, but not WIN 8, but it's in WIN 10....  The web has every font imaginable to mankind on it, yet nobody will ever google "Download OLDENGL.ttf" when they need it and don't have it.  You have to provide that font for them, or else expect them to complain about it.  :P

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: LCD Time and Date Using Windows Font
« Reply #13 on: December 04, 2020, 10:19:44 am »
Good effort, but it looks more like a VFD* display.

* Vacuum fluorescent display

FellippeHeitor

  • Guest
Re: LCD Time and Date Using Windows Font
« Reply #14 on: December 04, 2020, 10:33:32 am »
Dang I had no idea Steve! I said "highest" because that's the highest number it uses on Microsoft Wordpad. I just threw in a size 120 on a test and it's HUGE! Thank you!!!

Word processors show fonts measured in points. In QB64 you specify a size in pixels (height).