-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFourteenSegment.cpp
49 lines (42 loc) · 1.42 KB
/
FourteenSegment.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
#include "FourteenSegment.h"
#include <vector>
#include "Digit.h"
using std::vector;
FourteenSegment::FourteenSegment(uint8_t cathodes [], uint8_t anodes [15], uint8_t numDigits) {
for (int i = 0; i < numDigits; i++) {
auto* digit = new Digit(cathodes[i], anodes);
digits.push_back(digit);
}
this->numDigits = numDigits;
}
void FourteenSegment::drawString(String str) {
if (str.length() > numDigits)
str = str.substring(0, numDigits);
for (unsigned int i = 0; i < str.length(); i++) {
digits[i]->drawChar(' ');
digits[i]->show();
digits[i]->drawChar(str.charAt(i));
digits[i]->hide();
}
}
void FourteenSegment::enableDecimalPoint(int digit, bool enable) {
if (enable) {
digits[digit]->drawSegment(14);
} else {
digits[digit]->eraseSegment(14);
}
}
void FourteenSegment::wraparoundString(const String& str, int switchingTime) {
unsigned long initialTime = millis();
for (int i = 0; i < str.length(); i += numDigits) {
while (millis() < initialTime + ((i + numDigits) / numDigits) * switchingTime)
drawString(str.substring(i));
}
}
void FourteenSegment::rotateString(const String& str, int switchingTime) {
unsigned long initialTime = millis();
for (int i = 0; i < str.length() + 1; i++) {
while (millis() < initialTime + (i + 1) * switchingTime)
drawString(str.substring(i));
}
}