-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLC5928.cpp
More file actions
92 lines (80 loc) · 1.55 KB
/
Copy pathTLC5928.cpp
File metadata and controls
92 lines (80 loc) · 1.55 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
#include"TLC5928.h"
TLC5928::TLC5928(uint8_t clk, uint8_t data, uint8_t latch, uint8_t blank, uint8_t num) : pin_clk(clk), pin_data(data), pin_latch(latch), pin_blank(blank), num(num)
{
}
TLC5928::~TLC5928(){
delete [] buffer;
}
void TLC5928::begin()
{
buffer = new byte[num*16];
for(uint16_t i=0; i<num*16;i++ )
{
buffer[i]=0;
}
pinMode(pin_clk, OUTPUT);
pinMode(pin_data, OUTPUT);
pinMode(pin_latch, OUTPUT);
pinMode(pin_blank, OUTPUT);
digitalWrite(pin_clk, LOW);
digitalWrite(pin_data, LOW);
digitalWrite(pin_latch, LOW);
digitalWrite(pin_blank, LOW);
}
void TLC5928::setPixel(uint16_t numpi, bool on)
{
buffer[numpi]=on ? 1 : 0;
}
void TLC5928::setPixel(uint16_t numtlc, uint16_t numpi, bool on)
{
setPixel(numtlc*16+numpi, on);
}
void TLC5928::on()
{
digitalWrite(pin_blank, LOW);
delayMicroseconds(1);
}
void TLC5928::off()
{
digitalWrite(pin_blank, HIGH);
delayMicroseconds(1);
}
void TLC5928::show()
{
for(int i = num*16-1;i>=0;i--)
{
writeBit(buffer[i]);
}
digitalWrite(pin_latch, HIGH);
delayMicroseconds(1);
digitalWrite(pin_latch, LOW);
delayMicroseconds(1);
}
void TLC5928::clear()
{
for(int i = num*16-1;i>=0;i--)
{
buffer[i]=0;
writeBit(buffer[i]);
}
digitalWrite(pin_latch, HIGH);
delayMicroseconds(1);
digitalWrite(pin_latch, LOW);
delayMicroseconds(1);
}
void TLC5928::writeBit(bool on)
{
if(on)
{
digitalWrite(pin_data, HIGH);
}
else
{
digitalWrite(pin_data, LOW);
}
delayMicroseconds(1);
digitalWrite(pin_clk, LOW);
delayMicroseconds(1);
digitalWrite(pin_clk, HIGH);
delayMicroseconds(1);
}