Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RF22_MAX_test_Send
Diff: TextLCDScroll.cpp
- Revision:
- 0:0ae9963c4e06
- Child:
- 2:66723c542cef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCDScroll.cpp Tue Mar 27 20:13:41 2012 +0000
@@ -0,0 +1,106 @@
+#include "TextLCDScroll.h"
+#include "mbed.h"
+
+#include <string>
+using namespace std;
+
+ TextLCDScroll::TextLCDScroll(PinName rs, PinName e, PinName d4, PinName d5,
+ PinName d6, PinName d7, TextLCD::LCDType type): TextLCD(rs,e,d4,d5,d6,d7,type) {
+
+ _direction = new int[rows()];
+ _actPos = new int[rows()];
+ _stringArray = new string[rows()];
+ for (int i=0; i<rows(); i++) {
+ _direction[i]=1;
+ _actPos[i] = 0;
+ _stringArray[i] = "";
+ }
+ _spaces = string(columns(),' ');
+ //_mode = leftright;
+ _mode = left;
+
+ setSpeed(5);
+
+ }
+
+
+ bool TextLCDScroll::setLine( int Line, string str) {
+ if (Line >= 0 && Line < rows()) {
+ if ((str.length() > columns()) && (_mode == left))
+ _stringArray[Line] = _spaces + str + _spaces;
+ else
+ _stringArray[Line] = str;
+
+ // be sure to refresh the display
+ cls();
+ // start at beginning again
+ _actPos[Line] = 0;
+ _direction[Line] =1;
+ return(true);
+ } else {
+ return (false);
+ }
+ }
+
+ bool TextLCDScroll::setSpeed( int speed) {
+ if ((speed >= 0.1) && (speed <= 10)) {
+ tick.detach();
+ if (_mode == leftright)
+ tick.attach(this,&TextLCDScroll::ScrollRightLeft, 1.0/speed);
+ else
+ tick.attach(this,&TextLCDScroll::ScrollLeft, 1.0/speed);
+ return(true);
+ } else {
+ return(false);
+ }
+ }
+
+ bool TextLCDScroll::setScrollMode( ScrollModes mode) {
+ _mode = mode;
+ return(true);
+ }
+
+ void TextLCDScroll::ScrollRightLeft() {
+ int i;
+ for (i=0; i<rows(); i++) {
+ locate(0,i);
+ if (_stringArray[i].length() > columns()) {
+ printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
+ if (_direction[i] == 1) {
+ if (_stringArray[i].length() > _actPos[i]+columns()) {
+ _actPos[i] += 1;
+ } else {
+ _direction[i] = -1;
+ }
+ } else {
+ if (_actPos[i] > 0) {
+ _actPos[i] -= 1;
+ } else {
+ _direction[i]=1;
+ }
+ }
+ } else {
+ printf(_stringArray[i].c_str());
+ }
+ }
+ }
+
+ void TextLCDScroll::ScrollLeft() {
+ int i;
+ for (i=0; i<rows(); i++) {
+ locate(0,i);
+ if (_stringArray[i].length() > columns()) {
+ printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
+ if (_direction[i] == 1) {
+ if (_stringArray[i].length() > _actPos[i]+columns()) {
+ _actPos[i] += 1;
+ } else {
+ _actPos[i]=0;
+ }
+ }
+ } else {
+ printf(_stringArray[i].c_str());
+ }
+ }
+ }
+