forked from adafruit/Adafruit_TLC59711
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlc59711test.ino
115 lines (93 loc) · 3 KB
/
tlc59711test.ino
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************
This is an example for our Adafruit 12-channel PWM/LED driver
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/
These drivers uses SPI to communicate, 2 pins are required to
interface: Data and Clock. The boards are chainable
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include "Adafruit_TLC59711.h"
#include <SPI.h>
// How many boards do you have chained?
#define NUM_TLC59711 2
#define data 11
#define clock 13
Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711, clock, data);
//Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711);
void setup() {
Serial.begin(9600);
Serial.println("TLC59711 test");
// Uncomment this line if using UNO/AVR since 10 has to be an output
// for hardware SPI to work
//pinMode(10, OUTPUT);
tlc.begin();
tlc.write();
}
void loop() {
colorWipe(65535, 0, 0, 100); // "Red" (depending on your LED wiring)
delay(200);
colorWipe(0, 65535, 0, 100); // "Green" (depending on your LED wiring)
delay(200);
colorWipe(0, 0, 65535, 100); // "Blue" (depending on your LED wiring)
delay(200);
increaseBrightness();
}
// Fill the dots one after the other with a color
void colorWipe(uint16_t r, uint16_t g, uint16_t b, uint8_t wait) {
for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
tlc.setLED(i, r, g, b);
tlc.write();
delay(wait);
}
}
// Rainbow all LEDs at the same time, same color
void rainbow(uint8_t wait) {
uint32_t i, j;
for(j=0; j<65535; j+=10) {
for(i=0; i<4*NUM_TLC59711; i++) {
Wheel(i, (i+j) & 65535);
}
tlc.write();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint32_t i, j;
for(j=0; j<65535; j+=10) { // 1 cycle of all colors on wheel
for(i=0; i < 4*NUM_TLC59711; i++) {
Wheel(i, ((i * 65535 / (4*NUM_TLC59711)) + j) & 65535);
}
tlc.write();
delay(wait);
}
}
// Input a value 0 to 4095 to get a color value.
// The colours are a transition r - g - b - back to r.
void Wheel(uint8_t ledn, uint16_t WheelPos) {
if(WheelPos < 21845) {
tlc.setLED(ledn, 3*WheelPos, 65535 - 3*WheelPos, 0);
} else if(WheelPos < 43690) {
WheelPos -= 21845;
tlc.setLED(ledn, 65535 - 3*WheelPos, 0, 3*WheelPos);
} else {
WheelPos -= 43690;
tlc.setLED(ledn, 0, 3*WheelPos, 65535 - 3*WheelPos);
}
}
//All RGB Channels on full colour
//Cycles trough all brightness settings from 0 up to 127
void increaseBrightness(){
for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
tlc.setLED(i, 65535, 65535, 65535);
}
for(int i = 0; i < 128; i++){
tlc.simpleSetBrightness(i);
tlc.write();
delay(1000);
}
}