Ability to scroll lines in 4x20 display
Don M
Posts: 1,653
I need some help in understanding how to do this. If anyone has some examples or sample code it would be much appreciated.
What I have is a 4x20 display with a rotary encoder and I want the ability to scroll through received data sent to the display. Lets say for example I have a buffer I want to scroll through that has 300 bytes of characters in it. The display is only capable of 80 at a time.
So what I am thinking is there needs to be a way that I can store the 300 bytes of characters maybe in an array? And then be able to scroll through the array in 20 byte chunks only moving the lines up or down depending on the turn of the encoder.
I have no idea how to do this or if it can even be done.
Thanks for your help.
Don
What I have is a 4x20 display with a rotary encoder and I want the ability to scroll through received data sent to the display. Lets say for example I have a buffer I want to scroll through that has 300 bytes of characters in it. The display is only capable of 80 at a time.
So what I am thinking is there needs to be a way that I can store the 300 bytes of characters maybe in an array? And then be able to scroll through the array in 20 byte chunks only moving the lines up or down depending on the turn of the encoder.
I have no idea how to do this or if it can even be done.
Thanks for your help.
Don
Comments
For LC-Display-characters an array of bytes is sufficient
I haven't tested the code below. It is meant as a raw template to give you an idea how it can be done
The buffer contains the 300 ASCII-codes of the data you want to display.
mabye you have to add a command to switch to the next line
keep the questions coming
best regards
Stefan
The use of constant is to optimize the code a bit so that the math operations are done at compile time and a fixed value is inserted into the actual bytecode.
The #> and <# are used to constrain the values in one shot instead of doing multiple evaluations.
The code simplifies scrolling by simply sending the direction the encoder has turned. This allows you to use standard encoder reading objects that return direction.
http://obex.parallax.com/objects/576/
Thanks.
Don
pedward- what does the variable "offset" in the method DisplayBuffer(offset) represent?
Help!
If so I'd still suggest to use my driver, as it takes care of all. I checked it with the LCD_menu.spin demo which comes with the driver. It uses exactly what you need for the scrolling:
This line will start the driver
Setup of lines which use a buffer:
In CMD_SETLEN you specify the width of the line. In the demo it's 11 because I want some cursor-characters on the left and on the right. You would simply set it to 40.
With CMD_SETLINE you specify the start-position for a line. $40 is the LCD-address of the 2nd line, so specifying $42 means that the 3rd character of line 2 is the start of the characters controlled by the buffer. ($00,$40,$14 and $54 are the start addresses of the different lines of the display.) @menu is the address of the buffer itself.
In my demo-code I setup 3 lines for a menu using the same buffer at different positions. Of course you can also setup 3 lines with 3 different buffers of different size ... or only 1 line with 1 buffer.
Scrolling all 3 lines is then as easy as that: where 14 and (255-13) is the number of characters to scroll and <<16 / <<8 / <<0 tells which line to scroll.
So, scrolling only one line 40 characters looks like
LCD.exec( LCD#CMD_OTSCROLL, 40 )
In your code you simply update the buffer as you like. It's like a screen-buffer and the display-driver will take care of refreshing the LCD.
No need to create an extra buffer.
And scrolling works with:
Maybe you can extend the if statements a bit to avoid scrolling when you reached the boundaries.