-
Notifications
You must be signed in to change notification settings - Fork 2
/
TM1637Display.h
54 lines (43 loc) · 1.36 KB
/
TM1637Display.h
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
// Functions for 4-Digit display with TM1637 chip
// Code Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
// written by m.stroh
#ifndef __TM1637Display__
#define __TM1637Display__
#include <map>
// data types
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
class TM1637Display {
public:
static const BYTE cnMaxBrightness = 7;
static const BYTE cnDisplayAddress = 0xC0; //1. digit
static const BYTE cnDataCmdAutoAddr = 0x40;
static const BYTE cnDataCmdFixAddr = 0x44;
static const BYTE cnDisplayOn = 0x88; // + B0, B1, B2 = Brightness
public:
TM1637Display(BYTE clockPin, BYTE dataPin, BYTE BrightnessPercent);
~TM1637Display();
void Clear();
void Show(BYTE DigitNumber, const char Data);
void Show(const char* pData);
void Show(int Data);
void SetBrightness(BYTE BrightnessPercent); // 0...100
void ShowDoublePoint(bool bShow);
private:
BYTE m_Brightness;
bool m_bShowDP;
BYTE m_CLKPin;
BYTE m_DIOPin;
char m_CurrentData[5];
std::map<BYTE, char> m_Char2SegCode;
bool m_bACKErr;
private:
void writeByte(BYTE data);
void start(void);
void stop(void);
void Init7SegMap();
BYTE GetSegCode(BYTE DigitNumber, const char Data); //char to binary code for display
void CLKWait();
};
#endif // __TM1637Display__