Dies ist ein kleines Beispielprogramm:
#define NUM_TLCS 3
#define NUM_ROWS 8
#define NUM_COLUMNS 8
#include "Tlc5940Mux.h"
volatile uint8_t isShifting;
uint8_t shiftRow;
byte red[8 * 8] = {255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255};
byte green[8 * 8] = { 0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0};
byte blue[8 * 8] = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 0, 255, 0, 255, 255, 255,
255, 255, 255, 0, 255, 0, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};
byte blue2[8 * 8] = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 0, 255, 0, 255, 255,
255, 255, 0, 255, 0, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};
// SHIFT_DATA_PIN (PC0 is analog 0) = '595 SER pin (Pin 14)
#define SHIFT_DATA_PORT PORTC
#define SHIFT_DATA_PIN PC0
#define SHIFT_DATA_DDR DDRC
// SHIFT_CLK_PIN (PC1 is analog 1) = '595 SRCLK (Pin 11)
#define SHIFT_CLK_PORT PORTC
#define SHIFT_CLK_PIN PC1
#define SHIFT_CLK_DDR DDRC
// '595 RCLK is hooked to tlc XLAT pin (Arduino digital Pin 9, 74HC595 Pin 12)
int led_red;
int led_green;
int led_blue;
static inline void
shift8_595_row(uint8_t row)
{
// the output of the '595 for the selected row should be low, all others
// high
uint8_t output = (1 << row);
for (uint8_t bit = 0x80; bit; bit >>= 1) {
if (bit & output) {
SHIFT_DATA_PORT |= _BV(SHIFT_DATA_PIN);
} else {
SHIFT_DATA_PORT &= ~_BV(SHIFT_DATA_PIN);
}
// pulse the '595 sclk
SHIFT_CLK_PORT |= _BV(SHIFT_CLK_PIN);
SHIFT_CLK_PORT &= ~_BV(SHIFT_CLK_PIN);
}
}
ISR(TIMER1_OVF_vect)
{
if (!isShifting) {
disable_XLAT_pulses();
isShifting = 1;
sei();
TlcMux_shiftRow(shiftRow);
shift8_595_row(shiftRow);
shiftRow++;
if (shiftRow == NUM_ROWS) {
shiftRow = 0;
}
enable_XLAT_pulses();
isShifting = 0;
}
}
void setup()
{
SHIFT_DATA_DDR |= _BV(SHIFT_DATA_PIN);
SHIFT_CLK_DDR |= _BV(SHIFT_CLK_PIN);
TlcMux_init();
}
void loop()
{
for (byte Wiederholung = 0; Wiederholung <= 50; Wiederholung++)
{
for (uint8_t row = 0; row < NUM_ROWS; row++)
{
for (uint8_t col = 0; col < NUM_COLUMNS; col++)
{
Matrix_Pixel(row, col, red[(row * 8) + col], green[(row * 8) + col], blue[(row * 8) + col]);
}
}
delay(500);
for (uint8_t row = 0; row < NUM_ROWS; row++)
{
for (uint8_t col = 0; col < NUM_COLUMNS; col++)
{
Matrix_Pixel(row, col, red[(row * 8) + col], green[(row * 8) + col], blue2[(row * 8) + col]);
}
}
delay(500);
}
RandomLight(NUM_ROWS, NUM_COLUMNS, 100, 250);
}
void RandomLight(byte NumRow, byte NumColumn, int Wiederholung, int Geschw)
{
for (int Nr = 1; Nr <= Wiederholung; Nr += 1)
{
for (int Reihe = 0; Reihe < NumRow ; Reihe += 1)
{
for (int Zeile = 0; Zeile <= NumColumn; Zeile += 1)
{
Matrix_Pixel(Reihe, Zeile, random(255), random(255), random(255));
}
}
delay(Geschw);
}
}
void Matrix_Pixel(uint8_t row, uint8_t column, byte red, byte green, byte blue)
{
led_red = map(red, 0, 255, 0, 4095);
led_green = map(green, 0, 255, 0, 4095);
led_blue = map(blue, 0, 255, 0, 4095);
TlcMux_set(row, column, led_red / 1.8);
TlcMux_set(row, column + 16, led_green);
TlcMux_set(row, column + 32, led_blue);
}