This repository was archived by the owner on Mar 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLD5161B.cpp
More file actions
230 lines (205 loc) · 4.28 KB
/
LD5161B.cpp
File metadata and controls
230 lines (205 loc) · 4.28 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <Wire.h>
#include <PCF8574.h>
#include "./LD5161B.h"
/**
* The default constructor. Allows creating an empty array with
* LD5161B objects.
*
* @constructor
*/
LD5161B::LD5161B() {
// This constructor is empty.
}
/**
* @param uint8_t deviceAddress Address to the expander.
*/
LD5161B::LD5161B(const uint8_t deviceAddress) {
this->expander.begin(deviceAddress);
for (int i = 0; i < 8; ++i) {
this->expander.pinMode(i, OUTPUT);
this->expander.digitalWrite(i, HIGH);
}
}
/**
* Turns off all the LEDs.
*
* @return void
*/
void LD5161B::off() {
for (int i = 0; i < 8; ++i) {
this->expander.digitalWrite(i, HIGH);
}
}
/**
* Shows given number on 7. segment display.
*
* @param unsigned short number Number to display.
* @return void
*/
void LD5161B::show(const unsigned short number) {
switch (number) {
case 0:
this->displayZero();
break;
case 1:
this->displayOne();
break;
case 2:
this->displayTwo();
break;
case 3:
this->displayThree();
break;
case 4:
this->displayFour();
break;
case 5:
this->displayFive();
break;
case 6:
this->displaySix();
break;
case 7:
this->displaySeven();
break;
case 8:
this->displayEight();
break;
case 9:
this->displayNine();
break;
default:
this->off();
}
}
/**
* Shows number "0".
*
* @return void
*/
void LD5161B::displayZero() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(3, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(7, LOW);
}
/**
* Shows number "1".
*
* @return void
*/
void LD5161B::displayOne() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(4, LOW);
}
/**
* Shows number "2".
*
* @return void
*/
void LD5161B::displayTwo() {
this->off();
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(3, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
}
/**
* Shows number "3".
*
* @return void
*/
void LD5161B::displayThree() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
}
/**
* Shows number "4".
*
* @return void
*/
void LD5161B::displayFour() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(6, LOW);
this->expander.digitalWrite(7, LOW);
}
/**
* Shows number "5".
*
* @return void
*/
void LD5161B::displayFive() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
this->expander.digitalWrite(7, LOW);
}
/**
* Shows number "6".
*
* @return void
*/
void LD5161B::displaySix() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(3, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
this->expander.digitalWrite(7, LOW);
this->expander.digitalWrite(0, LOW);
}
/**
* Shows number "7".
*
* @return void
*/
void LD5161B::displaySeven() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
}
/**
* Shows number "8".
*
* @return void
*/
void LD5161B::displayEight() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(3, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
this->expander.digitalWrite(7, LOW);
}
/**
* Shows number "9".
*
* @return void
*/
void LD5161B::displayNine() {
this->off();
this->expander.digitalWrite(1, LOW);
this->expander.digitalWrite(2, LOW);
this->expander.digitalWrite(4, LOW);
this->expander.digitalWrite(5, LOW);
this->expander.digitalWrite(6, LOW);
this->expander.digitalWrite(7, LOW);
this->expander.digitalWrite(0, LOW);
}