Trying to scroll a message across an LED display

This is a discussion on Trying to scroll a message across an LED display within the C Programming forums, part of the General Programming Boards category; Hi! I am trying to scroll a block of text across a segmented LED screen but I am unable to ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    Trying to scroll a message across an LED display

    Hi!

    I am trying to scroll a block of text across a segmented LED screen but I am unable to have the entire message scroll across.

    I have been able to scroll the letters one at a time and upon reaching the end, the next letter begins. I've also been able to scroll the message across but the letters constantly change as they scroll.

    I am trying to achieve this type of scroll:

    - - - - - - - c
    - - - - - - c o
    - - - - - c o d
    - - - - c o d e
    - - - c o d e -
    - - c o d e - -
    - c o d e - - -
    c o d e - - - -
    o d e - - - - -
    d e - - - - - -
    e - - - - - - -
    - - - - - - - -
    repeat...

    However, I cannot figure out the way to work my increments/decrements in my function.


    this is the code i wrote to control the scrolling/increments/decrements but I can't figure out how to write it so to achieve the goal.
    Code:
    void write_chars(int digit)
    {
         int position;
         int space = 8;
       
         position = NUM_DISPLAYS - 1;
         
         do{
       
               write_letter(digit, position);
               position--;
               digit++;
               write_space(space--);
    
               
               Sleep(DELAY_TIME);
               
           }while(position > -2 );
    }
    
    
    void write_letter(int ch, int position)
    {
         static char chars_table[] = {131, 163, 179, 143};
         
         write_display(chars_table[ch], position);
    }
    
    
    void write_space(int position)
    {
         int pos;
         
         for ( pos = position; pos < NUM_DISPLAYS; pos++ )
         {
             write_display(SPACE_CH, pos);
         }         
    }



    Could someone be kind enough to help/guide me to the solution to this problem? (probably seems too easy but I just can't figure it out. Frustrating.)

    thanks..

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Step 1. Start at position n-1, like you've got.
    Step 2. Write spaces to get there.
    Step 3. Start writing the whole thing until you run out of space or word.
    Step 4. Write spaces for the rest of the line, if needed.
    Step 5. Decrease position by 1.

    When you start at a negative position, that means you need to skip some letters.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    Quote Originally Posted by tabstop View Post
    Step 2. Write spaces to get there.
    Step 3. Start writing the whole thing until you run out of space or word.
    I'm not quite following this part. I am not sure how to implement that. To me, that seems like it would come out to be quite long in terms of code length. Or is there a way to loop those two steps so that the text can scroll but have just a limited number of steps and simpler, less confusing code?

    But, I've tried different loop combinations and haven't been able to reach any success.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I suppose it depends on your definition of "long". I can't see a way to do it in any shorter than four lines, and conversely, I can't see a way to do it in any longer than four lines either. Step 2 is a for loop that just writes a space; step 3 is a for loop that just writes the appropriate letter. The ending condition on the for loop would be that you are both (1) not past the end of the word AND (2) not past the end of the physical display.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    Sorry for all the hassle but I tried it and I can't get the conditions right in order for it to display properly. Currently, I have it as this but it skips positions so it ends up writing to every other display and it won't repeat the text.

    Code:
    void write_chars()
    {
         int position = NUM_DISPLAYS - 1;
         int pos;
         int digit = 3;
         
         for(position = NUM_DISPLAYS - 1; position > NUM_DISPLAYS - 9; position--)
         {
                write_letter(digit, position);
                position--;
                digit--;
                Sleep(DELAY_TIME);
         }
         
         for(pos = NUM_DISPLAYS - 1; pos > position && pos > NUM_DISPLAYS - 9; pos--)
         {
                write_display(SPACE_CH, pos - 1);
         }
    
    }   
    
    void write_letter(int character, int position)
    {
         static char chars_table[] = {131, 163, 179, 143};
         
         write_display(chars_table[character], position);
    }

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You must have eight, and exactly eight, write_something commands between every sleep (I'm basing this on your picture of an 8-character display). You must write <i> spaces, <j> letters, and then <k> spaces, where the numbers i, j, and k are going to change as the word scrolls -- and they can be 0 (for instance, if the word is still off the right side of the display, k will be zero). So that means you need three for loops: the first to write <i> spaces, the second to write <j> letters, and the third to write <k> spaces. So for each line above (each "step" in the animation), work out how to find i, j, and k.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-19-2006, 09:30 PM
  2. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. Problem with Scroll Bar
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 11-05-2001, 05:34 AM
  5. Problem with Scroll Bar
    By Garfield in forum Windows Programming
    Replies: 3
    Last Post: 11-01-2001, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21