I have built a test matrix 2*2 rgb LED's, common Anode. Connected the anodes into columns, and the Cathodes trough 220R resistors into R,G,B rows. Both go to two different 74hc595 shift registers. I am then using this code to light up two LED's diagonally from an atmega48 connected to the registers (bottom left and top right).
/*
* RGBMatrix.c
*
* Created: 15.12.2017 23:35:52
* Author : Rando Hinn
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include "util/delay.h"
#define data_out PB2
#define shift_clock PB1
#define store_clock PB0
#define rgb_out PC5
#define rgbshift_clock PC4
#define rgbstore_clock PC3
#define SetBit(BIT, PORT) (PORT |= (1<<BIT))
#define ClearBit(BIT, PORT) (PORT &= ~(1<<BIT))
void shiftOut(uint8_t data) {
for(uint8_t i=0;i<8;i++) {
if(data & 0b10000000) {
SetBit(data_out, PORTB);
} else {
ClearBit(data_out, PORTB);
}
SetBit(shift_clock, PORTB);
ClearBit(shift_clock, PORTB);
data=data<<1;
}
SetBit(store_clock, PORTB);
ClearBit(store_clock, PORTB);
return;
}
void shiftOutRGB(uint8_t data) {
for(uint8_t i=0;i<8;i++) {
if(data & 0b10000000) {
SetBit(rgb_out, PORTC);
} else {
ClearBit(rgb_out, PORTC);
}
SetBit(rgbshift_clock, PORTC);
ClearBit(rgbshift_clock, PORTC);
data=data<<1;
}
SetBit(rgbstore_clock, PORTC);
ClearBit(rgbstore_clock, PORTC);
return;
}
int main(void)
{
DDRB|=((1<<shift_clock)|(1<<store_clock)|(1<<data_out));
DDRC|=((1<<rgbshift_clock)|(1<<rgbstore_clock)|(1<<rgb_out));
/*RCOL/LCOL*/
//shiftOut(0b10111111);
//shiftOutRGB(0b11010100);
/*BOT_R/BOT_G/BOT_B/TOP_R/TOP_G/TOP_B/NA/NA active low*/
while(1) {
shiftOutRGB(0b01111111);
shiftOut(0b01000000);
_delay_us(60);
shiftOutRGB(0b11111011);
shiftOut(0b10000000);
_delay_us(60);
}
}
The problem here is, that while I do get the LED's to light up, they are incredibly dim. Switching delays to ms, makes them brighter but causes visible flickering. What could I do to properly light the LED's?