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
TextLCDScroll.cpp@0:0ae9963c4e06, 2012-03-27 (annotated)
- Committer:
- charly
- Date:
- Tue Mar 27 20:13:41 2012 +0000
- Revision:
- 0:0ae9963c4e06
- Child:
- 2:66723c542cef
Initial version of TextLCDScroll
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| charly | 0:0ae9963c4e06 | 1 | #include "TextLCDScroll.h" |
| charly | 0:0ae9963c4e06 | 2 | #include "mbed.h" |
| charly | 0:0ae9963c4e06 | 3 | |
| charly | 0:0ae9963c4e06 | 4 | #include <string> |
| charly | 0:0ae9963c4e06 | 5 | using namespace std; |
| charly | 0:0ae9963c4e06 | 6 | |
| charly | 0:0ae9963c4e06 | 7 | TextLCDScroll::TextLCDScroll(PinName rs, PinName e, PinName d4, PinName d5, |
| charly | 0:0ae9963c4e06 | 8 | PinName d6, PinName d7, TextLCD::LCDType type): TextLCD(rs,e,d4,d5,d6,d7,type) { |
| charly | 0:0ae9963c4e06 | 9 | |
| charly | 0:0ae9963c4e06 | 10 | _direction = new int[rows()]; |
| charly | 0:0ae9963c4e06 | 11 | _actPos = new int[rows()]; |
| charly | 0:0ae9963c4e06 | 12 | _stringArray = new string[rows()]; |
| charly | 0:0ae9963c4e06 | 13 | for (int i=0; i<rows(); i++) { |
| charly | 0:0ae9963c4e06 | 14 | _direction[i]=1; |
| charly | 0:0ae9963c4e06 | 15 | _actPos[i] = 0; |
| charly | 0:0ae9963c4e06 | 16 | _stringArray[i] = ""; |
| charly | 0:0ae9963c4e06 | 17 | } |
| charly | 0:0ae9963c4e06 | 18 | _spaces = string(columns(),' '); |
| charly | 0:0ae9963c4e06 | 19 | //_mode = leftright; |
| charly | 0:0ae9963c4e06 | 20 | _mode = left; |
| charly | 0:0ae9963c4e06 | 21 | |
| charly | 0:0ae9963c4e06 | 22 | setSpeed(5); |
| charly | 0:0ae9963c4e06 | 23 | |
| charly | 0:0ae9963c4e06 | 24 | } |
| charly | 0:0ae9963c4e06 | 25 | |
| charly | 0:0ae9963c4e06 | 26 | |
| charly | 0:0ae9963c4e06 | 27 | bool TextLCDScroll::setLine( int Line, string str) { |
| charly | 0:0ae9963c4e06 | 28 | if (Line >= 0 && Line < rows()) { |
| charly | 0:0ae9963c4e06 | 29 | if ((str.length() > columns()) && (_mode == left)) |
| charly | 0:0ae9963c4e06 | 30 | _stringArray[Line] = _spaces + str + _spaces; |
| charly | 0:0ae9963c4e06 | 31 | else |
| charly | 0:0ae9963c4e06 | 32 | _stringArray[Line] = str; |
| charly | 0:0ae9963c4e06 | 33 | |
| charly | 0:0ae9963c4e06 | 34 | // be sure to refresh the display |
| charly | 0:0ae9963c4e06 | 35 | cls(); |
| charly | 0:0ae9963c4e06 | 36 | // start at beginning again |
| charly | 0:0ae9963c4e06 | 37 | _actPos[Line] = 0; |
| charly | 0:0ae9963c4e06 | 38 | _direction[Line] =1; |
| charly | 0:0ae9963c4e06 | 39 | return(true); |
| charly | 0:0ae9963c4e06 | 40 | } else { |
| charly | 0:0ae9963c4e06 | 41 | return (false); |
| charly | 0:0ae9963c4e06 | 42 | } |
| charly | 0:0ae9963c4e06 | 43 | } |
| charly | 0:0ae9963c4e06 | 44 | |
| charly | 0:0ae9963c4e06 | 45 | bool TextLCDScroll::setSpeed( int speed) { |
| charly | 0:0ae9963c4e06 | 46 | if ((speed >= 0.1) && (speed <= 10)) { |
| charly | 0:0ae9963c4e06 | 47 | tick.detach(); |
| charly | 0:0ae9963c4e06 | 48 | if (_mode == leftright) |
| charly | 0:0ae9963c4e06 | 49 | tick.attach(this,&TextLCDScroll::ScrollRightLeft, 1.0/speed); |
| charly | 0:0ae9963c4e06 | 50 | else |
| charly | 0:0ae9963c4e06 | 51 | tick.attach(this,&TextLCDScroll::ScrollLeft, 1.0/speed); |
| charly | 0:0ae9963c4e06 | 52 | return(true); |
| charly | 0:0ae9963c4e06 | 53 | } else { |
| charly | 0:0ae9963c4e06 | 54 | return(false); |
| charly | 0:0ae9963c4e06 | 55 | } |
| charly | 0:0ae9963c4e06 | 56 | } |
| charly | 0:0ae9963c4e06 | 57 | |
| charly | 0:0ae9963c4e06 | 58 | bool TextLCDScroll::setScrollMode( ScrollModes mode) { |
| charly | 0:0ae9963c4e06 | 59 | _mode = mode; |
| charly | 0:0ae9963c4e06 | 60 | return(true); |
| charly | 0:0ae9963c4e06 | 61 | } |
| charly | 0:0ae9963c4e06 | 62 | |
| charly | 0:0ae9963c4e06 | 63 | void TextLCDScroll::ScrollRightLeft() { |
| charly | 0:0ae9963c4e06 | 64 | int i; |
| charly | 0:0ae9963c4e06 | 65 | for (i=0; i<rows(); i++) { |
| charly | 0:0ae9963c4e06 | 66 | locate(0,i); |
| charly | 0:0ae9963c4e06 | 67 | if (_stringArray[i].length() > columns()) { |
| charly | 0:0ae9963c4e06 | 68 | printf(_stringArray[i].substr(_actPos[i],columns()).c_str()); |
| charly | 0:0ae9963c4e06 | 69 | if (_direction[i] == 1) { |
| charly | 0:0ae9963c4e06 | 70 | if (_stringArray[i].length() > _actPos[i]+columns()) { |
| charly | 0:0ae9963c4e06 | 71 | _actPos[i] += 1; |
| charly | 0:0ae9963c4e06 | 72 | } else { |
| charly | 0:0ae9963c4e06 | 73 | _direction[i] = -1; |
| charly | 0:0ae9963c4e06 | 74 | } |
| charly | 0:0ae9963c4e06 | 75 | } else { |
| charly | 0:0ae9963c4e06 | 76 | if (_actPos[i] > 0) { |
| charly | 0:0ae9963c4e06 | 77 | _actPos[i] -= 1; |
| charly | 0:0ae9963c4e06 | 78 | } else { |
| charly | 0:0ae9963c4e06 | 79 | _direction[i]=1; |
| charly | 0:0ae9963c4e06 | 80 | } |
| charly | 0:0ae9963c4e06 | 81 | } |
| charly | 0:0ae9963c4e06 | 82 | } else { |
| charly | 0:0ae9963c4e06 | 83 | printf(_stringArray[i].c_str()); |
| charly | 0:0ae9963c4e06 | 84 | } |
| charly | 0:0ae9963c4e06 | 85 | } |
| charly | 0:0ae9963c4e06 | 86 | } |
| charly | 0:0ae9963c4e06 | 87 | |
| charly | 0:0ae9963c4e06 | 88 | void TextLCDScroll::ScrollLeft() { |
| charly | 0:0ae9963c4e06 | 89 | int i; |
| charly | 0:0ae9963c4e06 | 90 | for (i=0; i<rows(); i++) { |
| charly | 0:0ae9963c4e06 | 91 | locate(0,i); |
| charly | 0:0ae9963c4e06 | 92 | if (_stringArray[i].length() > columns()) { |
| charly | 0:0ae9963c4e06 | 93 | printf(_stringArray[i].substr(_actPos[i],columns()).c_str()); |
| charly | 0:0ae9963c4e06 | 94 | if (_direction[i] == 1) { |
| charly | 0:0ae9963c4e06 | 95 | if (_stringArray[i].length() > _actPos[i]+columns()) { |
| charly | 0:0ae9963c4e06 | 96 | _actPos[i] += 1; |
| charly | 0:0ae9963c4e06 | 97 | } else { |
| charly | 0:0ae9963c4e06 | 98 | _actPos[i]=0; |
| charly | 0:0ae9963c4e06 | 99 | } |
| charly | 0:0ae9963c4e06 | 100 | } |
| charly | 0:0ae9963c4e06 | 101 | } else { |
| charly | 0:0ae9963c4e06 | 102 | printf(_stringArray[i].c_str()); |
| charly | 0:0ae9963c4e06 | 103 | } |
| charly | 0:0ae9963c4e06 | 104 | } |
| charly | 0:0ae9963c4e06 | 105 | } |
| charly | 0:0ae9963c4e06 | 106 |