-
Notifications
You must be signed in to change notification settings - Fork 1
/
Samsung_16LF01_VFD.cpp
170 lines (148 loc) · 4.16 KB
/
Samsung_16LF01_VFD.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Samsung_16LF01_VFD - Library for Samsung 16LF01 series 16 segments
* vacuum fluorescent displays (VFD).
*
* Full tested with the Samsung 16LF01UA3 display.
*
* This library tries to be compatible with the LiquidCrystal library.
*
* Copyright (c) 2015 Daniele Napolitano <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Samsung_16LF01_VFD.h"
/**
* When the display powers up, it is configured as follows:
* Position: 1
* Digits count: 16
* Brightness: 0
**/
Samsung_16LF01_VFD::Samsung_16LF01_VFD(uint8_t _SCLK, uint8_t _DATA, uint8_t _RST) {
// Set internals
_sclk_pin = _SCLK;
_data_pin = _DATA;
_rst_pin = _RST;
// Configure pins
pinMode(_sclk_pin, OUTPUT);
pinMode(_data_pin, OUTPUT);
pinMode(_rst_pin, OUTPUT);
}
// Init the display with 16 digits and mid level brightness
void Samsung_16LF01_VFD::begin(uint8_t digits_count = 16, uint8_t brightness = 15) {
// First reset the display
reset();
// Then set the digits count (default: 16)
setDigitsCount(digits_count);
// So, clear the digit buffer
clear();
// Then light up the display (with buffer clear, no random RAM data)
setBrightness(brightness);
}
// Blank the display by setting up to 16 spaces
void Samsung_16LF01_VFD::clear() {
setCursor(0);
for (int i=0; i<_digits_count; i++) {
write(' ');
}
}
// Return to position 1
void Samsung_16LF01_VFD::home() {
setCursor(0);
}
// Set buffer poiner position.
void Samsung_16LF01_VFD::setCursor(uint8_t pos) {
if (pos > 15) {
pos = 15;
}
// First digit value is B1111, from second start from 0
if (pos == 0) {
pos = B1111;
}
else {
pos--;
}
pos &= VFD_CMD_MASK;
sendCommand(VFD_CMD_BUFFER_POINTER | pos);
}
// Set display brightness, from 0 to 31.
void Samsung_16LF01_VFD::setBrightness(uint8_t amount) {
if (amount > 31) {
amount = 31;
}
amount &= VFD_CMD_BRIGHTNESS_MASK;
sendCommand(VFD_CMD_BRIGHTNESS | amount);
}
// Write a char on the display
inline size_t Samsung_16LF01_VFD::write(uint8_t _char) {
// First set of charmap (letters ad some symbols)
if (_char >= 64 && _char <= 95) {
sendCommand(_char - 64);
}
// Second set of charmap (numbers and some symbols)
else if (_char >= 32 && _char <= 63) {
sendCommand(_char);
}
// Lower case letters
else if (_char >= 97 && _char <= 122) {
sendCommand(_char - 96);
}
// If we get a return carrier, return to position 0.
if (_char == '\r' || _char == '\n') {
setCursor(0);
}
return 1;
}
// Reset the display.
void Samsung_16LF01_VFD::reset() {
// Spec needs RST signal for above 1ms
digitalWrite(_rst_pin, LOW);
delay(2);
digitalWrite(_rst_pin, HIGH);
delay(2);
}
// Send serial data to the display
void Samsung_16LF01_VFD::sendCommand(uint8_t data) {
for (int i=7; i>=0; i--) {
digitalWrite(_data_pin, bitRead(data, i));
digitalWrite(_sclk_pin, HIGH);
delayMicroseconds(2);
digitalWrite(_sclk_pin, LOW);
delayMicroseconds(2);
digitalWrite(_sclk_pin, HIGH);
// Internal processing time (40us)
delayMicroseconds(40);
}
}
// Set number of digits to control.
void Samsung_16LF01_VFD::setDigitsCount(uint8_t digits = 16) {
if (digits > 16) {
digits = 16;
}
_digits_count = digits;
digits &= VFD_CMD_MASK;
sendCommand(VFD_CMD_DIGIT_COUNTER | digits);
}
// Reset the display.
void Samsung_16LF01_VFD::iniciar() {
// Spec needs RST signal for above 1ms
digitalWrite(_rst_pin, LOW);
delay(2);
digitalWrite(_rst_pin, HIGH);
delay(2);
}