forked from iamthechad/parallax_lcd
/
ParallaxLCD.cpp
executable file
·137 lines (113 loc) · 3.25 KB
/
ParallaxLCD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
NOTE: you must: #include <SoftwareSerial.h>
BEFORE including the class header file
For Parallax LCD's (27976, 27977, 27979)
For more information contact http://www.parallax.com
Updated to Arduino 1.0 by Chad Johnston (cjohnston@megatome.com)
July 11, 2012
Original Work done by:
Douglas Farrell
cyberblob59@yahoo.com
Used/Modified with permission from allen joslin
--Based on SparkFunSerLCD.h from--
allen joslin
payson productions
allen@joslin.net
*/
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "ParallaxLCD.h"
#define PINOUT 0
#define POSBASE 1
#define BOUNCE 2
#define NUMROWS 3
#define NUMCOLS 4
ParallaxLCD::ParallaxLCD ( int pin, int numRows, int numCols, int posBase) : SoftwareSerial(pin,pin) {
_bv[PINOUT]=pin;
_bv[POSBASE]=posBase;
_bv[BOUNCE]=10;
_bv[NUMROWS]=numRows;
_bv[NUMCOLS]=numCols;
_ro[0]=0;
_ro[1]=64;
_ro[2]=numCols;
_ro[3]=_ro[1]+numCols;
}
void ParallaxLCD::setup(boolean startEmpty ) {
pinMode(_bv[PINOUT], OUTPUT);
delay(_bv[BOUNCE]);
begin(19200);
delay(_bv[BOUNCE]);
if (startEmpty) {
empty();
}
cursorOff();
}
void ParallaxLCD::on () {
write(24); delay(_bv[BOUNCE]);
}
void ParallaxLCD::off () {
write(21); delay(_bv[BOUNCE]);
}
void ParallaxLCD::scrollLeft () {
print(8); delay(_bv[BOUNCE]);
}
void ParallaxLCD::scrollRight () {
write(9); delay(_bv[BOUNCE]);
}
void ParallaxLCD::empty () {
write(12); delay(_bv[BOUNCE]*10);
}
void ParallaxLCD::cursorUnderline () {
write(24); delay(_bv[BOUNCE]);
}
void ParallaxLCD::cursorBlock () {
write(23); delay(_bv[BOUNCE]);
}
void ParallaxLCD::cursorOff () {
write(22); delay(_bv[BOUNCE]);
}
void ParallaxLCD::cursorOnChrBlink () {
write(25); delay(_bv[BOUNCE]);
}
void ParallaxLCD::cr () {
write(13); delay(_bv[BOUNCE]);
}
void ParallaxLCD::lf () {
write(10); delay(_bv[BOUNCE]);
}
void ParallaxLCD::backLightOn () {
write(17); delay(_bv[BOUNCE]);
}
void ParallaxLCD::backLightOff () {
write(18); delay(_bv[BOUNCE]);
}
void ParallaxLCD::pos ( int row, int col )
{
if (row == 0)
{
write(128 + _ro[(row - _bv[POSBASE])] + (col - _bv[POSBASE])); delay(_bv[BOUNCE]);
}
else if (row == 1)
{
write(148 + _ro[(row - _bv[POSBASE])] + (col - _bv[POSBASE])); delay(_bv[BOUNCE]);
}
else if (row == 2)
{
write(168 + _ro[(row - _bv[POSBASE])] + (col - _bv[POSBASE])); delay(_bv[BOUNCE]);
}
else if (row == 3)
{
write(188 + _ro[(row - _bv[POSBASE])] + (col - _bv[POSBASE])); delay(_bv[BOUNCE]);
}
}
// shortcuts
void ParallaxLCD::at ( int row, int col, char v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, const char v[] ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, String v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, uint8_t v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, int v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, unsigned int v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, long v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, unsigned long v ) { pos(row,col); print(v); }
void ParallaxLCD::at ( int row, int col, long v, int t ) { pos(row,col); print(v,t); }