-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclock4digit.cpp
More file actions
80 lines (70 loc) · 1.76 KB
/
Copy pathclock4digit.cpp
File metadata and controls
80 lines (70 loc) · 1.76 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
#include "clock4digit.h"
// AA
// F B
// F B
// GG
// E C
// E C
// DD
//
// GECAxFDB
static const uint8_t digits[10] = {
0b01110111, // 0
0b00100001, // 1
0b11010011, // 2
0b10110011, // 3
0b10100101, // 4
0b10110110, // 5
0b11110110, // 6
0b00110001, // 7
0b11110111, // 8
0b10110101 // 9
};
Clock4digit::Clock4digit(int data, int wr, int cs): Ht162x(data, wr, cs) {}
void Clock4digit::begin(){
init();
sendCommand(0b001010010); // Bias 1/3, 10/4 commons
sendCommand(0b000110000); // Internal RC 256K
sendCommand(0b000001010); // Disable WDT
sendCommand(0b000001000); // Disable time base output
sendCommand(0b000000010); // Turn on system oscillator
sendCommand(0b000000110); // LCD on
}
void Clock4digit::setDigit(uint8_t pos, uint8_t value) {
if (pos >= 4 || value >= 10)
return;
auto pattern = digits[value];
for (int a = 0; a < 4; a++) {
auto data = _displayData[a];
bitWrite(data, pos, bitRead(pattern, a));
bitWrite(data, pos + 4, bitRead(pattern, a + 4));
sendData8(a, data);
}
}
void Clock4digit::setSymbol(uint8_t symbol, bool enable) {
uint8_t addr = symbol >> 3;
uint8_t bitnum = symbol & 0x07;
uint8_t mask = ~bit(bitnum);
uint8_t tmp = _displayData[addr];
tmp = tmp & mask;
if (enable) {
tmp = tmp | bit(bitnum);
}
sendData8(addr, tmp);
}
bool Clock4digit::getSymbol(uint8_t symbol) {
uint8_t addr = symbol >> 3;
uint8_t bitnum = symbol & 0x07;
uint8_t tmp = _displayData[addr];
return (tmp & bit(bitnum)) != 0;
}
void Clock4digit::setNumber(uint16_t value, uint8_t len, uint8_t offset){
auto tmp = value;
updateBegin();
for(uint8_t x = 0; x < len; x++){
auto digit = tmp % 10;
tmp = tmp / 10;
setDigit(offset + x, digit);
}
updateEnd();
}