-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlc.cpp
80 lines (70 loc) · 2.15 KB
/
tlc.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
/***************************************************************************
* *
* Arduino Library for the TLC59731 *
* (c) 2018 Nathan Shaffer *
* *
* *
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU License. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU License V2 for more details. *
* *
***************************************************************************/
#include "Arduino.h"
#include "tlc.h"
//#include <math.h>
#ifdef auto_pad
#endif
void tlc::writeBit(uint8_t data)
{
digitalWrite(pin_out, HIGH);
digitalWrite(pin_out, LOW);
if(data)
{
digitalWrite(pin_out, HIGH);
digitalWrite(pin_out, LOW);
delayMicroseconds(high_bit_pad);
}
else
{
delayMicroseconds(low_bit_pad);
}/**/
}
void tlc::writeByte(uint8_t data)
{
writeBit(data & (1<<7));
writeBit(data & (1<<6));
writeBit(data & (1<<5));
writeBit(data & (1<<4));
writeBit(data & (1<<3));
writeBit(data & (1<<2));
writeBit(data & (1<<1));
writeBit(data & (1<<0));
}
void tlc::EOS()
{
delayMicroseconds(eos_length );
}
void tlc::gsDataLatchSequence()
{
delayMicroseconds(latch_length );
}
void tlc::writeLed(uint8_t r, uint8_t g, uint8_t b, bool latch = true)
{
writeByte(B00111010);
writeByte(r);
writeByte(g);
writeByte(b);
if(latch)
{
gsDataLatchSequence();
}
else
{
EOS();
}
}