Scrolling text on a CLCD or CVFD

Applications, examples, and sample programs using products from Comfile Technology

Scrolling text on a CLCD or CVFD

Postby Garrett » Tue Nov 14, 2006 1:43 pm

Response to a request by Jeff for a way to scroll text sideways on an LCD.

The current implementation of CLCD or CVFD does not support hardware scrolling. However, the CUBLOC and CuNET interface is fast enough to scroll by redrawing the entire line. My code determines which piece of the text should be displayed and then outputs that part using the MID function.

This code is experimental and there are likely enhancements for flexibility and efficiency. However, it works well and is a good place to start!

Code: Select all
' Character Display Scrolling Example
' Garrett Mace
' Comfile Technology 11/13/2006

' This code is provided as-is and is not intended for use in situations involving
' risk of injury to property or persons.

Const Device = CB290

Const DisplayWidth = 20 ' Set to the width of your display
Const ScrollDelay = 200 ' Adjust for desired scrolling speed


'Display initialization - must be changed to match your display
Set Display 2,0,0,32         'Set display to CLCD/CVFD
Cls                        'Clear screen
Print &H1B, &H73             'Turn off cursor

Dim ScrollMessage As String * 40
Dim i As Byte
Dim MessageLength As Byte

ScrollMessage = "Now playing: CB290 Blues by The Comfiles"
MessageLength = Len(ScrollMessage)


' Main program loop
Do

Gosub Bounce ' Text scrolls to the end one direction, then scrolls the other way
'Gosub Marquee ' Text scrolls in from the right edge and scrolls completely off the screen

Loop



' Code to scroll in a bounce style
Bounce:

   For i = 1 To MessageLength - DisplayWidth + 1
      Locate 0,0
      Print Mid(ScrollMessage,i,DisplayWidth)
      Delay ScrollDelay
   Next

   Delay 5*ScrollDelay

   For i = MessageLength - DisplayWidth To 1 Step -1
      Locate 0,0
      Print Mid(ScrollMessage,i,DisplayWidth)
      Delay ScrollDelay
   Next

   Delay 5*ScrollDelay

Return

' Code to scroll in a marquee style
Marquee:

   For i = 1 To DisplayWidth
      Locate DisplayWidth-i,0
      Print Left(ScrollMessage, i)
      Delay ScrollDelay
   Next

   For i = 2 To MessageLength - (DisplayWidth - 1)
      Locate 0,0
      Print Mid(ScrollMessage,i,DisplayWidth)
      Delay ScrollDelay
   Next   

   For i = MessageLength - (DisplayWidth - 2) To MessageLength+1
      Locate 0,0
      Print Mid(ScrollMessage,i,MessageLength-i+1)
      If (MessageLength-i) < (DisplayWidth)) Then Print " "
      Delay ScrollDelay
   Next
Return
User avatar
Garrett
Site Admin
 
Posts: 475
Joined: Tue Nov 07, 2006 1:04 pm
Location: Cubloc HQ

Re: Scrolling text on a CLCD or CVFD

Postby Guido84 » Sun Jan 17, 2010 2:07 pm

Where can i find the code to expand 4X20 CLCD TO a 16 X 20 CLCD
Guido84
MasterGoo
 
Posts: 2
Joined: Sun Jan 17, 2010 12:57 pm

Re: Scrolling text on a CLCD or CVFD

Postby opeongo » Sat Oct 30, 2010 6:23 pm

Hello Garrett; I tried to load this program into a CB280 Study kit. I am using a 2 line by 16 character lcd I2c display.

I got an error message for this line.

If (MessageLength-i) < (DisplayWidth)) Then Print " "

The error message was:
Syntax Error ! invalid parenthesis At line 76
If (MessageLength-i) < (DisplayWidth)) Then Print " "

Is there something simple that is out of order. I am software neophyte.
------------------------------------------------------------------------------------

Here is your program which I changed to suit the CB280.

' Character Display Scrolling Example
' Garrett Mace
' Comfile Technology 11/13/2006

' This code is provided as-is and is not intended for use in situations involving
' risk of injury to property or persons.

Const Device = CB280

Const DisplayWidth = 16 ' Set to the width of your display
Const ScrollDelay = 200 ' Adjust for desired scrolling speed


'Display initialization - must be changed to match your display
Set Display 2,0,0,32 'Set display to CLCD/CVFD
Cls 'Clear screen
Print &H1B, &H73 'Turn off cursor

Dim ScrollMessage As String * 40
Dim i As Byte
Dim MessageLength As Byte

ScrollMessage = "Now playing: CB280 Blues by The Comfiles"
MessageLength = Len(ScrollMessage)


' Main program loop
Do

Gosub Bounce ' Text scrolls to the end one direction, then scrolls the other way
'Gosub Marquee ' Text scrolls in from the right edge and scrolls completely off the screen

Loop



' Code to scroll in a bounce style
Bounce:

For i = 1 To MessageLength - DisplayWidth + 1
Locate 0,0
Print Mid(ScrollMessage,i,DisplayWidth)
Delay ScrollDelay
Next

Delay 5*ScrollDelay

For i = MessageLength - DisplayWidth To 1 Step -1
Locate 0,0
Print Mid(ScrollMessage,i,DisplayWidth)
Delay ScrollDelay
Next

Delay 5*ScrollDelay

Return

' Code to scroll in a marquee style
Marquee:

For i = 1 To DisplayWidth
Locate DisplayWidth-i,0
Print Left(ScrollMessage, i)
Delay ScrollDelay
Next

For i = 2 To MessageLength - (DisplayWidth - 1)
Locate 0,0
Print Mid(ScrollMessage,i,DisplayWidth)
Delay ScrollDelay
Next

For i = MessageLength - (DisplayWidth - 2) To MessageLength+1
Locate 0,0
Print Mid(ScrollMessage,i,MessageLength-i+1)
If (MessageLength-i) < (DisplayWidth)) Then Print " "
Delay ScrollDelay
Next
Return
opeongo
MasterGoo
 
Posts: 1
Joined: Sat Oct 30, 2010 6:09 pm


Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron