Hier nochmal mein Sketch:
#define NUM_TLCS 3 // Hier Anzahl der verwendeten TLC5940 hinschreiben
#define NUM_ROWS 16 // Anzahl der ROWS der Matrix
#define NUM_COLUMNS 8 // An zahl der Columns der Matrix
#include "Tlc5940Mux.h"
//#define __AVR_ATmega2560__
volatile uint8_t isShifting;
uint8_t shiftRow;
// SHIFT_DATA_PIN (PF0 is analog 0) = '595 SER pin
#define SHIFT_DATA_PORT PORTF
#define SHIFT_DATA_PIN PF0
#define SHIFT_DATA_DDR DDRF
// SHIFT_CLK_PIN (PF1 is analog 1) = '595 SRCLK
#define SHIFT_CLK_PORT PORTF
#define SHIFT_CLK_PIN PF1
#define SHIFT_CLK_DDR DDRF
// '595 RCLK is hooked to tlc XLAT pin
uint16_t Led_Red;
uint16_t Led_Green;
uint16_t 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);
uint8_t output = (1 << row); // Eventuell beides mal probieren
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;
}
}
const int MatrixWidth = NUM_ROWS;
const int MatrixHeight = NUM_COLUMNS;
int PixelColor[MatrixWidth+1][MatrixHeight+1][4];
void setup()
{
SHIFT_DATA_DDR |= _BV(SHIFT_DATA_PIN);
SHIFT_CLK_DDR |= _BV(SHIFT_CLK_PIN);
TlcMux_init();
}
void loop()
{
for(int i = 1; i <= MatrixWidth; i++)
{
for(int j = 1; j <= MatrixHeight; j++)
{
PixelColor[i][j][1] = 255;
PixelColor[i][j][2] = 0;
PixelColor[i][j][3] = 0;
}
}
Render();
delay(10);
}
void Render()
{
Display();
}
void Display()
{
for(int i = 1; i <= MatrixWidth; i++)
{
for(int j = 1; j <= MatrixHeight; j++)
{
Matrix_Pixel(i, j, PixelColor[i][j][1], PixelColor[i][j][2], PixelColor[i][j][3]);
}
}
}
void Clear()
{
for(int i = 1; i <= MatrixWidth; i++)
{
for(int j = 1; j <= MatrixHeight; j++)
{
PixelColor[i][j][1] = 0;
PixelColor[i][j][2] = 0;
PixelColor[i][j][3] = 0;
}
}
}
void Matrix_Pixel(uint8_t Row, uint8_t Column, byte Red, byte Green, byte Blue)
{
Row -= 1;
Column -= 1;
Led_Red = map(Red, 0, 255, 0, 4095);
Led_Green = map(Green, 0, 255, 0, 4095);
Led_Blue = map(Blue, 0, 255, 0, 4095);
if(Row < 8)
{
TlcMux_set(Row, Column, Led_Red / 1.8);
TlcMux_set(Row, Column+16, Led_Green);
TlcMux_set(Row, Column+32, Led_Blue);
}
else
{
TlcMux_set(Row-7, Column+8, Led_Red / 1.8);
TlcMux_set(Row-7, Column+16+8, Led_Green);
TlcMux_set(Row-7, Column+32+8, Led_Blue);
}
}
Was meint ihr: Ich hab ja den Mega2560 2x. Soll ich je 16x8 bzw. 8x16 mit einem Mega verbinden, sprich zwei Arduinos benutzen, von denen jeder die halbe Matrix ansteuert?
Dann müsste ich allerdings die Platinen umlöten und die Arduinos auch noch synchronisieren. Oder hat jemand ne andere Idee,
warum bei einer bestimmten Anzahl von LEDs manche Pixel verrückt spielen?