Shop OBEX P1 Docs P2 Docs Learn Events
How do I Create a 7-Segment (LED type) Numeric font for video/vga — Parallax Forums

How do I Create a 7-Segment (LED type) Numeric font for video/vga

laser-vectorlaser-vector Posts: 118
edited 2010-07-30 05:51 in Propeller 1
this is probably a noob question but i was wondering if anybody knew how i could generate numbers that look like 7 segment displays for VGA??

Thanks

Post Edited (laser-vector) : 7/29/2010 11:56:53 PM GMT

Comments

  • ForrestForrest Posts: 1,341
    edited 2010-07-29 23:43
    Google LED font
  • potatoheadpotatohead Posts: 10,261
    edited 2010-07-30 05:06
    Which driver are you using? If it's the parallax one, you could write a few SPIN methods that draw the led segments off of a given origin. Number them 0 - X number of segments, and have them all work off a common X, Y, maybe in the upper left corner, or from the center, or whatever.

    Then to draw characters, you just set the X and Y, and call all the segments you want lit. If you provide a color argument to those methods, you could then also erase with the same code. Look at the google fonts, get some graph paper, and graph them out, using a grid size that you think will look good. Then code them in terms of lines and the fill command you find in graphics.spin.

    Imagine a small 8 pixel by 8 pixel square as a sample of how to do a segment. It's drawn a coordinate that is aligned with it's upper left corner...

    The line segments would be 0,0 - 0,8 : 0,8 - 8,8 : 8,8 - 8,0 : 8,0 - 0,0

    Here is some sample code that illustrates what is needed to build up the two methods you will need to draw complete characters on the screen at a given position.


    A segment would look like:

    PUB draw_segment(x, y, segment, color)
    
        case segment
          00 : colorwidth(color, 1)    'segment 0
               plot(x, y)
               line(x, Y + 8)
               line(x + 8, y)
               plot(x + 8, y + 8)
               line(x + 8, y)
               line(x, Y + 8)
       (fill, and I've not used that one yet)
               
               
          01 : colorwidth(color, 1)    'segment 1
               plot(x, y)
               line(x, Y + 8)
               line(x + 8, y)
               plot(x + 8, y + 8)
               line(x + 8, y)
               line(x, Y + 8)
        (fill again)
    
    PUB  LED_char(x, y, character, color)
    
         case character
            00 : draw_segment(x, y, 1, color)
                 draw_segment(x, y, 3, color)
    
            01 :  continue this...
    
            done!
    
    
    
    



    You've only got to get the 7 segments drawn out, then you can write another routine to "print" with the LED font, that calls the segments required for the characters.

    If you want to, you could scale those numbers to make them bigger or smaller too. Just multiply before adding and drawing.

    Notice I've got more than one line drawn from a plot point. I think that's the behavior. If not, just draw each line with a plot, followed by a line, and it will all be good, just a tad slower.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Wondering how to set tile colors in the graphics_demo.spin?
    Safety Tip: Life is as good as YOU think it is!

    Post Edited (potatohead) : 7/30/2010 5:29:05 AM GMT
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-30 05:38
    Awesome!! thanks potatohead

    ill give that a shot tomorrow!
  • potatoheadpotatohead Posts: 10,261
    edited 2010-07-30 05:51
    I just thought about something else. If you've only a few characters, like the numbers, this will work sweet.

    If there are a ton of them, you might consider storing the line segments in the DAT section, with some special values to terminate a character. You can then change the LED_char to read from the DAT section, and just draw all the segments for that character.

    DAT

    char0 byte 1,4,6, 255
    char1 byte 1,3,4, 255
    char2 byte 0,3,5, 255

    You can get rid of the case statement in there, and just have a repeat until loop that draws the segments it finds for the character. Keep knocking out segments until reaching the 255, which just isn't a segment, and can serve as a marker for end of character.

    Chip wrote something that works like that for the text in graphics.spin Look that over, for a good example of how to pack all the characters into a DAT, using the SPIN procedures to draw them as needed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Wondering how to set tile colors in the graphics_demo.spin?
    Safety Tip: Life is as good as YOU think it is!

    Post Edited (potatohead) : 7/30/2010 6:26:20 AM GMT
Sign In or Register to comment.