mirror of
https://github.com/PaulStoffregen/Tlc5940
synced 2025-09-27 01:52:20 +02:00
Import Tlc5940 version r014_2
This commit is contained in:
BIN
examples/BasicAnimations/AnimationCreator.class
Normal file
BIN
examples/BasicAnimations/AnimationCreator.class
Normal file
Binary file not shown.
86
examples/BasicAnimations/AnimationCreator.java
Normal file
86
examples/BasicAnimations/AnimationCreator.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* First Attempt at generating the TLC output code from an image.
|
||||
* Run this with "java AnimationCreator"
|
||||
* It will read any image file in the current directory and create an animation for the TLC library.
|
||||
*
|
||||
* Right now this only works with 1 TLC with 16 LEDS connected to it, where
|
||||
* output0 is the bottom and output15 is the top.
|
||||
*
|
||||
* For best results make your files 16 pixels high and as wide as you want. Each vertical pixel
|
||||
* corresponds to an LED output.
|
||||
*
|
||||
* Alex Leone <acleone ~AT~ gmail.com>, 2008-11-12
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import javax.imageio.*;
|
||||
|
||||
public class AnimationCreator {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length == 0) {
|
||||
autoProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public static void autoProcess() throws IOException {
|
||||
File currentDirectory = new File (".");
|
||||
File[] files = currentDirectory.listFiles();
|
||||
int animationCount = 1;
|
||||
for (File file : files) {
|
||||
if (!file.isFile())
|
||||
continue;
|
||||
String fileName = file.getName();
|
||||
String suffix = fileName.substring(fileName.indexOf('.') + 1);
|
||||
if(!canReadFormat(suffix))
|
||||
continue;
|
||||
String baseName = fileName.substring(0, fileName.indexOf('.'));
|
||||
String varName = "ani_" + baseName.toLowerCase();
|
||||
String outputName = varName + ".h";
|
||||
System.out.println("Writing " + outputName);
|
||||
BufferedImage image = ImageIO.read(file);
|
||||
PrintStream output = new PrintStream(new File(outputName));
|
||||
output.println("#define " + varName.toUpperCase() + "_FRAMES " + image.getWidth());
|
||||
output.println("uint8_t " + varName + "[NUM_TLCS * 24 * " + varName.toUpperCase() + "_FRAMES] PROGMEM = {");
|
||||
int[] rowRGB = new int[16];
|
||||
for (int w = 0; w < image.getWidth(); w++) {
|
||||
for (int h = 0; h < 16; h++) {
|
||||
rowRGB[h] = image.getRGB(w, 15 - h);
|
||||
}
|
||||
parseRow(rowRGB, output);
|
||||
}
|
||||
output.println("};");
|
||||
System.out.println("Wrote " + image.getWidth() + " frames to " + outputName);
|
||||
animationCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the specified format name can be read
|
||||
public static boolean canReadFormat(String formatName) {
|
||||
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName(formatName);
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
public static double rgbToGrayscaleIntensity(int rgb) {
|
||||
Color c = new Color(rgb);
|
||||
return 0.2989 * c.getRed() + 0.5870 * c.getGreen() + 0.1140 * c.getBlue();
|
||||
}
|
||||
|
||||
public static void parseRow(int[] rowRGB, PrintStream output) {
|
||||
output.print("\t");
|
||||
for (int i = rowRGB.length - 1; i >= 0; i -= 2) {
|
||||
int a = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i])));
|
||||
int b = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1])));
|
||||
output.print(((a >> 4) & 0xFF) + "," + (((a << 4) | (b >> 8)) & 0xFF) + "," + (b & 0xFF) + ",");
|
||||
//System.out.print(
|
||||
// "GS_DUO(" + (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i]))) + "," +
|
||||
// (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1]))) + "),");
|
||||
}
|
||||
output.println();
|
||||
}
|
||||
|
||||
|
||||
}
|
BIN
examples/BasicAnimations/Arduino.png
Normal file
BIN
examples/BasicAnimations/Arduino.png
Normal file
Binary file not shown.
52
examples/BasicAnimations/BasicAnimations.pde
Normal file
52
examples/BasicAnimations/BasicAnimations.pde
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Writes "Ardunio" with Persistance of Vision (POV) with 16 LEDs (output 0
|
||||
is on bottom, output 15 is top). The animation below doesn't work with
|
||||
more than 1 TLC.
|
||||
|
||||
I generated the animation with the included java code:
|
||||
<arduino folder>/hardware/libraries/Tlc5940/examples/BasicAnimations
|
||||
|
||||
To use the code, run
|
||||
java AnimationCreator
|
||||
in the folder above and it will parse all images in the folder to
|
||||
.h files. For best results use images that are 16 pixels high.
|
||||
|
||||
See the BasicUse example for hardware setup.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
#include "tlc_animations.h"
|
||||
#include "ani_arduino.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// checks to see if the animation is finished playing
|
||||
if (!tlc_onUpdateFinished) {
|
||||
|
||||
delay(100);
|
||||
|
||||
/*
|
||||
void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames,
|
||||
uint16_t periodsPerFrame);
|
||||
periods per frame is PWM periods, 1.024ms per frame (0 is valid - this
|
||||
will play the animation as fast as possible).
|
||||
|
||||
Plays an animation in the "background".
|
||||
Don't call Tlc.update() while this is running.
|
||||
You can check if this is done with !tlc_onUpdateFinished */
|
||||
tlc_playAnimation(ani_arduino, ANI_ARDUINO_FRAMES, 3);
|
||||
|
||||
|
||||
// If you don't want to do anything until it's finished, use:
|
||||
// while (!tlc_onUpdateFinished);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
84
examples/BasicAnimations/ani_arduino.h
Normal file
84
examples/BasicAnimations/ani_arduino.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#define ANI_ARDUINO_FRAMES 80
|
||||
uint8_t ani_arduino[NUM_TLCS * 24 * ANI_ARDUINO_FRAMES] PROGMEM = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,176,206,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,65,10,64,247,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,160,122,13,192,255,15,240,254,11,192,89,
|
||||
0,0,0,0,0,0,0,0,4,4,240,179,15,192,255,15,240,255,8,32,33,0,0,0,
|
||||
0,0,0,0,0,37,8,128,231,15,240,255,15,144,169,15,240,255,0,0,0,0,0,0,
|
||||
0,0,94,12,16,255,15,240,255,13,64,113,1,48,0,15,240,255,0,0,0,0,0,0,
|
||||
0,0,255,15,240,243,9,192,56,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0,
|
||||
0,0,255,15,240,243,9,208,57,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0,
|
||||
0,0,93,12,0,255,15,240,255,13,80,114,1,64,0,15,240,255,0,0,0,0,0,0,
|
||||
0,0,0,0,0,36,8,112,230,15,240,255,15,144,170,15,240,255,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,4,4,224,178,15,192,255,15,240,255,8,32,32,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,144,121,13,176,255,15,240,254,11,160,86,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,10,48,246,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,160,206,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,2,9,224,248,7,32,24,0,16,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,109,15,240,115,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,208,15,240,25,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,248,15,240,1,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,253,15,240,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,16,90,11,176,237,15,192,237,11,176,90,0,16,0,
|
||||
0,0,0,0,0,0,0,0,6,11,0,255,15,240,255,15,240,255,15,240,255,11,16,6,
|
||||
0,0,0,0,0,0,0,0,125,15,240,247,7,48,26,0,48,26,7,16,246,15,240,126,
|
||||
0,0,0,0,0,0,0,0,221,15,240,100,0,0,0,0,0,0,0,0,98,15,240,222,
|
||||
0,0,0,0,0,0,0,0,250,15,240,14,0,0,0,0,0,0,0,0,13,15,240,249,
|
||||
0,0,0,0,0,0,0,0,226,15,240,14,0,0,0,0,0,0,0,0,13,15,240,223,
|
||||
0,0,0,0,0,0,0,0,130,15,240,103,0,0,0,0,0,0,0,0,100,15,240,131,
|
||||
0,0,0,0,0,0,0,0,5,10,112,248,7,96,27,0,64,27,7,64,247,10,112,6,
|
||||
15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,253,14,144,173,3,32,0,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,144,57,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,2,224,201,15,240,186,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46,15,240,242,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,15,240,246,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,15,240,206,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,15,240,102,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,6,32,246,9,80,0,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,9,64,246,6,48,13,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,100,15,240,111,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,208,15,240,24,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,250,15,240,4,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,241,15,240,47,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,186,15,240,202,2,240,3,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,57,15,144,255,15,240,255,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,3,32,173,14,144,253,15,240,255,15,240,255,15,240,255,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,73,11,80,235,15,176,235,11,80,74,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,8,80,255,15,240,255,15,240,255,15,240,255,8,144,0,
|
||||
0,0,0,0,0,0,0,0,72,15,240,254,8,128,31,0,64,31,8,128,254,15,240,74,
|
||||
0,0,0,0,0,0,0,0,179,15,240,137,0,0,0,0,0,0,0,0,136,15,240,181,
|
||||
0,0,0,0,0,0,0,0,234,15,240,32,0,0,0,0,0,0,0,0,31,15,240,235,
|
||||
0,0,0,0,0,0,0,0,251,15,240,5,0,0,0,0,0,0,0,0,4,15,240,251,
|
||||
0,0,0,0,0,0,0,0,234,15,240,33,0,0,0,0,0,0,0,0,32,15,240,235,
|
||||
0,0,0,0,0,0,0,0,179,15,240,142,0,0,0,0,0,0,0,0,138,15,240,180,
|
||||
0,0,0,0,0,0,0,0,69,15,240,255,8,224,33,0,80,32,8,176,254,15,240,72,
|
||||
0,0,0,0,0,0,0,0,0,8,16,255,15,240,255,15,240,255,15,240,255,8,80,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,70,11,48,234,15,176,234,11,48,72,0,0,0,
|
||||
};
|
||||
|
101
examples/BasicUse/BasicUse.pde
Normal file
101
examples/BasicUse/BasicUse.pde
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Basic Pin setup:
|
||||
------------ ---u----
|
||||
ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
|
||||
12| OUT2 |2 27|-> GND (VPRG)
|
||||
11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
|
||||
10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
|
||||
9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
|
||||
8| . |6 23|-> BLANK (pin 10)
|
||||
7| . |7 22|-> GND
|
||||
6| . |8 21|-> VCC (+5V)
|
||||
5| . |9 20|-> 2K Resistor -> GND
|
||||
4| . |10 19|-> +5V (DCPRG)
|
||||
3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
|
||||
2| . |12 17|-> SOUT
|
||||
1| . |13 16|-> XERR
|
||||
0| OUT14|14 15| OUT channel 15
|
||||
------------ --------
|
||||
|
||||
- Put the longer leg (anode) of the LEDs in the +5V and the shorter leg
|
||||
(cathode) in OUT(0-15).
|
||||
- +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG)
|
||||
- GND from Arduino -> TLC pin 22 and 27 (GND and VPRG)
|
||||
- digital 3 -> TLC pin 18 (GSCLK)
|
||||
- digital 9 -> TLC pin 24 (XLAT)
|
||||
- digital 10 -> TLC pin 23 (BLANK)
|
||||
- digital 11 -> TLC pin 26 (SIN)
|
||||
- digital 13 -> TLC pin 25 (SCLK)
|
||||
- The 2K resistor between TLC pin 20 and GND will let ~20mA through each
|
||||
LED. To be precise, it's I = 39.06 / R (in ohms). This doesn't depend
|
||||
on the LED driving voltage.
|
||||
- (Optional): put a pull-up resistor (~10k) between +5V and BLANK so that
|
||||
all the LEDs will turn off when the Arduino is reset.
|
||||
|
||||
If you are daisy-chaining more than one TLC, connect the SOUT of the first
|
||||
TLC to the SIN of the next. All the other pins should just be connected
|
||||
together:
|
||||
BLANK on Arduino -> BLANK of TLC1 -> BLANK of TLC2 -> ...
|
||||
XLAT on Arduino -> XLAT of TLC1 -> XLAT of TLC2 -> ...
|
||||
The one exception is that each TLC needs it's own resistor between pin 20
|
||||
and GND.
|
||||
|
||||
This library uses the PWM output ability of digital pins 3, 9, 10, and 11.
|
||||
Do not use analogWrite(...) on these pins.
|
||||
|
||||
This sketch does the Knight Rider strobe across a line of LEDs.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
/* Call Tlc.init() to setup the tlc.
|
||||
You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
/* This loop will create a Knight Rider-like effect if you have LEDs plugged
|
||||
into all the TLC outputs. NUM_TLCS is defined in "tlc_config.h" in the
|
||||
library folder. After editing tlc_config.h for your setup, delete the
|
||||
Tlc5940.o file to save the changes. */
|
||||
|
||||
void loop()
|
||||
{
|
||||
int direction = 1;
|
||||
for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) {
|
||||
|
||||
/* Tlc.clear() sets all the grayscale values to zero, but does not send
|
||||
them to the TLCs. To actually send the data, call Tlc.update() */
|
||||
Tlc.clear();
|
||||
|
||||
/* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
|
||||
one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
|
||||
chained, then channel = 16 would be OUT0 of the second TLC, etc.).
|
||||
|
||||
value goes from off (0) to always on (4095).
|
||||
|
||||
Like Tlc.clear(), this function only sets up the data, Tlc.update()
|
||||
will send the data. */
|
||||
if (channel == 0) {
|
||||
direction = 1;
|
||||
} else {
|
||||
Tlc.set(channel - 1, 1000);
|
||||
}
|
||||
Tlc.set(channel, 4095);
|
||||
if (channel != NUM_TLCS * 16 - 1) {
|
||||
Tlc.set(channel + 1, 1000);
|
||||
} else {
|
||||
direction = -1;
|
||||
}
|
||||
|
||||
/* Tlc.update() sends the data to the TLCs. This is when the LEDs will
|
||||
actually change. */
|
||||
Tlc.update();
|
||||
|
||||
delay(75);
|
||||
}
|
||||
|
||||
}
|
||||
|
48
examples/CircularLightBuffer/CircularLightBuffer.pde
Normal file
48
examples/CircularLightBuffer/CircularLightBuffer.pde
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
A circular light buffer. If you manage to construct a circle of LEDs,
|
||||
definitely send in pictures. What this sketch does is take an analog
|
||||
reading off of analog pin 0 and add it to the current value of the last LED.
|
||||
If the resultant sum is greater than 4095, it turns the LED off,
|
||||
otherwise sets LED 0 to the value of the sum.
|
||||
|
||||
If you ground pin 12, it will set LED 0 to zero.
|
||||
|
||||
Then it shifts all the LED values up one (so LED 0 becomes LED 1) and sets
|
||||
LED 0 to the value shifted off the last LED (so if one LED is on, it will
|
||||
go in a circle forever).
|
||||
|
||||
See the BasicUse example for hardware setup.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-04 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
#include "tlc_shifts.h"
|
||||
|
||||
// which analog pin to use
|
||||
#define ANALOG_PIN 0
|
||||
|
||||
// which pin to clear the LEDs with
|
||||
#define CLEAR_PIN 12
|
||||
|
||||
// how many millis for one full revolution over all the LEDs
|
||||
#define SCOPE_PERIOD (2000 * NUM_TLCS)
|
||||
#define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(CLEAR_PIN, INPUT);
|
||||
digitalWrite(CLEAR_PIN, HIGH); // enable pull-up
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// shiftUp returns the value shifted off the last pin
|
||||
uint16_t sum = tlc_shiftUp() + analogRead(ANALOG_PIN) * 4;
|
||||
if (digitalRead(CLEAR_PIN) == LOW || sum > 4095)
|
||||
sum = 0;
|
||||
Tlc.set(0, sum);
|
||||
Tlc.update();
|
||||
delay(LED_PERIOD);
|
||||
}
|
||||
|
45
examples/FadeScope/FadeScope.pde
Normal file
45
examples/FadeScope/FadeScope.pde
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
A simple 1-d oscilliscope: scan all the channels, setting the PWM output
|
||||
value to 4x the analog pin 0 value (0 - 1024 * 4 = 4096). The value will
|
||||
fade to zero as the channels keep scanning.
|
||||
|
||||
See the BasicUse example for hardware setup.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
#include "tlc_fades.h"
|
||||
|
||||
// which analog pin to use
|
||||
#define ANALOG_PIN 0
|
||||
|
||||
// how many millis to strobe over all the LEDs
|
||||
#define SCOPE_PERIOD (1000 * NUM_TLCS)
|
||||
#define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
|
||||
|
||||
TLC_CHANNEL_TYPE channel;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t lastMillis = millis();
|
||||
tlc_addFade(channel, // led channel
|
||||
analogRead(ANALOG_PIN) * 4, // start fade value (0-4095)
|
||||
0, // end fade value (0-4095)
|
||||
lastMillis + 2, // start millis
|
||||
lastMillis + (uint16_t)SCOPE_PERIOD / 4 // end millis
|
||||
);
|
||||
if (channel++ == NUM_TLCS * 16) {
|
||||
channel = 0;
|
||||
}
|
||||
uint32_t currentMillis;
|
||||
do {
|
||||
currentMillis = millis();
|
||||
tlc_updateFades(currentMillis);
|
||||
} while (currentMillis - lastMillis <= LED_PERIOD);
|
||||
}
|
||||
|
38
examples/Fades/Fades.pde
Normal file
38
examples/Fades/Fades.pde
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Fades a line down the channels, with max value and duration based on
|
||||
the voltage of analog pin 0.
|
||||
Try grounding analog 0: everything should turn off.
|
||||
Try putting +5V into analog 0: everything should turn on.
|
||||
|
||||
See the BasicUse example for hardware setup.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
#include "tlc_fades.h"
|
||||
|
||||
TLC_CHANNEL_TYPE channel;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
|
||||
if (!tlc_isFading(channel)) {
|
||||
uint16_t duration = analogRead(0) * 2;
|
||||
int maxValue = analogRead(0) * 2;
|
||||
uint32_t startMillis = millis() + 50;
|
||||
uint32_t endMillis = startMillis + duration;
|
||||
tlc_addFade(channel, 0, maxValue, startMillis, endMillis);
|
||||
tlc_addFade(channel, maxValue, 0, endMillis, endMillis + duration);
|
||||
}
|
||||
if (channel++ == NUM_TLCS * 16) {
|
||||
channel = 0;
|
||||
}
|
||||
}
|
||||
tlc_updateFades();
|
||||
}
|
||||
|
40
examples/Servos/Servos.pde
Normal file
40
examples/Servos/Servos.pde
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This sketch sweeps a servo on channel 0.
|
||||
|
||||
To connect a servo:
|
||||
1. Put a 2k-5k pull-up resistor (R0 below; I've tried with 3.3k) between the
|
||||
servo control output pin and +5v.
|
||||
2. Connect that same pin to the servo's control line like so
|
||||
|
||||
servo data pin
|
||||
| _____
|
||||
OUTn ----+----[_____]---+5v
|
||||
R0
|
||||
|
||||
Steve Pomeroy <steve ~AT~ staticfree.info>, 2009-01-20 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
#include "tlc_servos.h"
|
||||
|
||||
#define SERVO_CHANNEL 0
|
||||
#define DELAY_TIME 20
|
||||
|
||||
void setup()
|
||||
{
|
||||
tlc_initServos(); // Note: this will drop the PWM freqency down to 50Hz.
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int angle = 0; angle < 180; angle++) {
|
||||
tlc_setServo(SERVO_CHANNEL, angle);
|
||||
Tlc.update();
|
||||
delay(DELAY_TIME);
|
||||
}
|
||||
for (int angle = 180; angle >= 0; angle--) {
|
||||
tlc_setServo(SERVO_CHANNEL, angle);
|
||||
Tlc.update();
|
||||
delay(DELAY_TIME);
|
||||
}
|
||||
}
|
||||
|
60
examples/UsingProgmem/UsingProgmem.pde
Normal file
60
examples/UsingProgmem/UsingProgmem.pde
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Setting grayscale from progmem to save RAM. If you want to play
|
||||
multiple "frames", (an animation), see the BasicAnimations Example.
|
||||
|
||||
See the BasicUse example for hardware setup.
|
||||
|
||||
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
|
||||
|
||||
#include "Tlc5940.h"
|
||||
|
||||
// Extended functions (they start with tlc_...) require another include
|
||||
#include "tlc_progmem_utils.h"
|
||||
|
||||
/*
|
||||
This is an array in program memory. Program memory is 16kB instead of
|
||||
1024 bytes for regular variables in SRAM.
|
||||
|
||||
The format for this array is
|
||||
GS_DUO(OUT15, OUT14), ... GS_DUO(OUT1, OUT0)
|
||||
|
||||
If you have more than one TLC, the format is
|
||||
GS_DUO(TLC2.OUT15, TLC2.OUT14), ... GS_DUO(TLC2.OUT1, TLC2.OUT0),
|
||||
GS_DUO(TLC1.OUT15, TLC1.OUT14), ... GS_DUO(TLC1.OUT1, TLC1.OUT0)
|
||||
|
||||
The pattern below will only work with 1 TLC. Copy + Paste the 4 lines
|
||||
inside the curly brackets for each additional TLC. */
|
||||
uint8_t gsArray1[NUM_TLCS * 24] PROGMEM = {
|
||||
GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16),
|
||||
GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16),
|
||||
GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16),
|
||||
GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16),
|
||||
};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Tlc.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Display the pattern (brightness ramp over the outputs)
|
||||
tlc_setGSfromProgmem(gsArray1);
|
||||
Tlc.update();
|
||||
|
||||
// Fade each channel to zero
|
||||
for (TLC_CHANNEL_TYPE channel = 0; channel < NUM_TLCS * 16; channel++) {
|
||||
int16_t initialValue = Tlc.get(channel);
|
||||
while (initialValue > 0) {
|
||||
initialValue -= 5;
|
||||
if (initialValue < 0) {
|
||||
initialValue = 0;
|
||||
}
|
||||
Tlc.set(channel, initialValue);
|
||||
|
||||
// wait until the data has been sent to the TLCs before continuing
|
||||
while (Tlc.update());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user