-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk16k33.cpp
94 lines (79 loc) · 1.84 KB
/
vk16k33.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
#include "vk16k33.h"
void vk16k33::refresh()
{
I2C_startWrite(this->i2c_address);
for(uint8_t i = 0; i < sizeof(this->data); i++)
I2C_write(this->data[i]);
I2C_stop();
}
void vk16k33::digit( uint8_t digit, uint8_t idx, bool dot)
{
data[idx * 2 + 1] = digits[digit] & 0xFF;
data[idx * 2 + 2] = digits[digit] >> 8;
if(dot)
{
data[idx * 2 + 2] |= (VK16K33_SEGMENT_DOT >> 8);
}
}
void vk16k33::clear()
{
memset(data, 0, sizeof(data));
}
void vk16k33::setI2CAddress(uint8_t newAddr)
{
this->i2c_address = newAddr;
}
void vk16k33::init()
{
this->brightness = 0;
I2C_startWrite(this->i2c_address);
I2C_write(VK16K33_CMD_INIT);
I2C_stop();
I2C_startWrite(this->i2c_address);
I2C_write(VK16K33_CMD_SETUP | VK16K33_CMD_DISPLAY_ON);
I2C_stop();
I2C_startWrite(this->i2c_address);
I2C_write(VK16K33_CMD_BRIGHTNESS);
I2C_stop();
}
void vk16k33::setBrightness(uint8_t br = 0)
{
if(br > 0xF) br = 0xF;
this->brightness = br;
I2C_startWrite(this->i2c_address);
I2C_write( VK16K33_CMD_BRIGHTNESS | br );
I2C_stop();
}
void vk16k33::setBlink(uint8_t blink)
{
if( (blink != VK16K33_BLINK_OFF) &&
(blink != VK16K33_BLINK_1HZ) &&
(blink != VK16K33_BLINK_2HZ) &&
(blink != VK16K33_BLINK_0HZ5) )
{
blink = VK16K33_BLINK_OFF;
}
I2C_startWrite(this->i2c_address);
I2C_write(VK16K33_CMD_SETUP | VK16K33_CMD_DISPLAY_ON | blink);
I2C_stop();
}
void vk16k33::decBrightness(void)
{
if(this->brightness != 0)
{
this->brightness--;
this->setBrightness(this->brightness);
}
}
void vk16k33::incBrightness(void)
{
if(this->brightness != 16)
{
this->brightness++;
this->setBrightness(this->brightness);
}
}
uint8_t vk16k33::getBrightness(void)
{
return this->brightness;
}