Shop OBEX P1 Docs P2 Docs Learn Events
7 segment display and alphabet... — Parallax Forums

7 segment display and alphabet...

eagletalontimeagletalontim Posts: 1,399
edited 2014-04-08 18:40 in Propeller 1
Is there a way to display letters on a 7 segment display via a DATA variable that is easier than ' Send_To_Display("letter", number_of_letter_in_alphabet) '? What I am trying to accomplish is to send a STRING to the single 7 segment display via a function and it split the string and display it letter by letter with a small delay between letters so it is readable. Any help is greatly appreciated!


*** EDIT : Nevermind, I figured it out :)

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-07 01:48
    7-segment displays have VERY LIMITED alpha capabilities

    A
    b
    C
    c
    d
    E
    F
    H
    I (same as one)
    J
    L
    n
    o
    0 (same as zero)
    P
    r
    S (same as five)
    t
    u

    If you cannot build your string with this set then a different display is in order. If these letter work, you'll need to build an array of segment masks to create the letters -- so long as you have individual segment control over the LEDs.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 17:41
    I wound up making a long data list of each letter and number and used lookdown to pinpoint which data index to use. It works except I can't use the code like this :
    numbers := 3
    Display(numbers)
    
    ' I have to use it like this :
    numbers := 3
    
    case numbers
      1:
        to_display := string("1")
      2:
        to_display := string("2")
      3:
        to_display := string("3")
    
    Display(to_display)
    
    ' **** Display Function
    
    PUB Display(todisplay) | x, i, pattern, str_size, Index
      x := 0
      BYTEMOVE(@DisplayStr, todisplay, strsize(todisplay))
      str_size := strsize(@DisplayStr)
    
      leds.init(LED_DATA, LED_LATCH)
      
      repeat str_size
        Index := lookdown(DisplayStr[x]: " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
        if Index > 0
          pattern := alpha[Index]
          dira[LED_Output_Enable]~~
          outa[LED_Output_Enable] := 1
          repeat i from 0 to 8
            leds.out(pattern, true)
            pattern >>= 1
          outa[LED_Output_Enable] := 0
          x++
          if x < str_size
            pause(500)
      bytefill(@DisplayStr, 0, 9)
      return
    
    DAT
    ' invalid letters : k, m, w, x, z
      alpha   byte %1011_0001, %0000_0000, %1111_0101, %0111_1100, %1101_1000, %0011_1101, %1111_1000, %1111_0000, %1110_1101, %0111_0101, %0101_0000, %0001_1101, %1011_0001, %0101_1000, %1011_0001, %0011_0100, %0011_1100, %1111_0001, %1011_0001, %0011_0000, %1110_1100, %0111_1000, %0001_1100, %0101_1101, %1011_0001, %1011_0001, %0110_1001, %1011_0001, %0000_0101, %1011_1001, %1010_1101, %0110_0101, %1110_1100, %1111_1100, %1000_0101, %1111_1111, %1101_1101, %1101_1101
    ' First index is a ? which will display if character not found.
    
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-07 17:43
    Use two tables. The first holds the offset into the second (which is the segment patterns). You can use simple math to convert the ASCII value to a table value.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 18:32
    I am not quite sure what you mean by using math to convert the ASCII value to a table value. Would like to learn it though.

    Right now, I am having difficulty sending menu data to the function.
    PUB Program_Mode | ok_to_exit, selected_menu
      ok_to_exit := 0
      selected_menu := 0
    
      Display(string("setup "))
      pause(1000)
      Display(string(" "))
      repeat while ok_to_exit == 0
        Display(lookup(selected_menu: _menuItems))    ' This is not working here.
        ok_to_exit := 1
    
      return 
    
    PUB Display(todisplay) | x, i, pattern, str_size, Index
      x := 0
      BYTEMOVE(@DisplayStr, todisplay, strsize(todisplay))
      str_size := strsize(@DisplayStr)
    
      leds.init(LED_DATA, LED_LATCH)
      
      repeat str_size
        Index := lookdown(DisplayStr[x]: " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
        if Index > 0
          pattern := alpha[Index]
          dira[LED_Output_Enable]~~
          outa[LED_Output_Enable] := 1
          repeat i from 0 to 8
            leds.out(pattern, true)
            pattern >>= 1
          outa[LED_Output_Enable] := 0
          x++
          if x < str_size
            pause(500)
      bytefill(@DisplayStr, 0, 9)
      return
    
    DAT
      _menuItems    word "menu 0", "menu 1", "menu 2", "menu 3"
    
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-07 19:05
    Here's an idea to consider: You have to tables in a DAT section; one for digits, one for alpha characters that can be represented in a 7-segment LED. Note that you don't have to test for everything, just what can be displayed. Here's a routine that will convert your character to a pattern.
    pub get_segments(c)
    
    '' Returns 7-segment pattern for character c
    
      if ((c => "0") and (c =< "9"))
        return DigitTable[c - "0"]
      else
        c := lookdown(c : " AbCcdEFHhIiJLlnoPrStUuY")
        if (c)
          return AlphaTable[c]
        else
          return 0
    


    I just noticed that you want to display "menu 0" -- this cannot be done on a 7-segment display as there is no way to do a "m". You might consider a 13-segment display if you really want to display words like this.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 19:19
    Ok, that made things a little more simpler. Thanks for that!

    Now, could you help me figure out how to use my display function like this :
    some_string := "test"
    Display(some_string)
    

    Or....
    selected_menu := 1
    Display(lookup(selected_menu: _menuItems))  ' this should output "?enu 1"  the (?) is because there since no way to display an "m" and lookdown will return 0.  I will just avoid using invalid characters.
    
    DAT
        _menuItems            word     "menu 0", "menu 1", etc....
    
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 19:57
    This is even more difficult than I thought :( I am also trying to use the Display function like this :

    number_value := 3
    Display(number_value)

    I can't seem to figure out what I am missing besides all values sent to the Display function must be sent using string("stuff")
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 20:28
    Ok, I figured out a few things and now I am still stuck at this code :
        ' this section is supposed to pull the menu text and run it through the "str" function.  It is not working.  I am actually not sure how to do this.
        selected_menu := 1
        display_string := lookup(selected_menu: _menuItems)
        str(display_string)
    
        ' Using the "str" function like this works...
        str(string("test")
    
    PUB str(stringptr)
      '' Send zero terminated string that starts at the stringptr memory address
      repeat strsize(stringptr)
        Display(byte[stringptr++])
        pause(500)
    
    DAT
        _menuItems            word     "select 0", "select 1", "select 2"
        '_menuItems            byte     "select 0", "select 1", "select 2"
        '_menuItems            long     "select 0", "select 1", "select 2"
    
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-07 20:37
    You need to read up on DAT tables -- what you have is completely bogus. While you're at it, look up the @@ operator as it allows you to create a table of addresses to strings (there's an example in the manual).
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-07 20:50
    Oh wow! I did not know about the @@ operator! Thank you sooo much! Got it figured out for now I think! Just tested it and it worked like a champ!
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-08 09:52
    You owe me a beer! :)
  • PublisonPublison Posts: 12,366
    edited 2014-04-08 09:55
    JonnyMac wrote: »
    You owe me a beer! :)

    Jon,

    There is at least 300 of us here that owe you a beer.

    Not at the same time, of course. :)

    Not to mention those that owe you from your various article over the years.

    Thank You,

    Jim
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2014-04-08 16:01
    Hi All;

    Back in the day a couple of us were trying to use a 7 segment LED calculator display as the output of a forth like controller. This language would use single character words.

    Since 7 segments can display 127 characters, 255 if you include the decimal point.

    Here is something we came up with.
    7SegmentForth.gif

    We never went very far with this, but it was a cool thought experiment.

    Duane J
    53 x 386 - 2K
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-08 16:55
    Here is a few for you!
    540 x 366 - 62K
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-08 18:27
    I need help again please :)

    I have gotten everything to work good so far until I ran into this issue....
    variable1 := 2
    variable2 := 750
    
    str(string("test"))  ' This works
    
    Display("t") ' this works
    
    Display(variable1 + "0") ' this works
    
    Display(variable2 + "0") ' this does not work :(
    
    str(variable2 + "0") ' this does not work :(
    

    If I need to post more code, please let me know. All the functions are the pretty much the same.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-08 18:30
    You need to break your numbers down into single digits.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-08 18:40
    Just figured that out :) Borrowing some code from FullDuplexSerialPlus. Thank you though for pointing that out.
Sign In or Register to comment.