Well, I thought, since I've been making things with the Arduino for quite some time I'd better have a go at an LED matrix, seems to be one of the standard early projects I skipped...
I'm using a 4017 logic IC to scan the matrix, each of the 4017's outputs is connected to a cathode row via an NPN transistor, the anode columns are driven directly off Arduino pins
This works perfectly well, except the row my program considers to be the first is always dimly lit, if I slow the scan rate down you can see it seems to be blinking when the 4017 goes around to the 0 output.
Heres a quick video that should demonstrate better whats going on that I can describe: http://www.beigematchbox.co.uk/forums/arduino/ledmatrix.mov
// LED Matrix test
// 8x10 Matrix using a 4017 logic chip
#include <MsTimer2.h>
#define CLOCK 3
#define RESET 2
const char led[] = {5, 6, 7, 8, 9, 10, 11, 12};
volatile char clockCount = 0;
char frame[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
void setup(){
Serial.begin(19200);
pinMode(CLOCK, OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
for (char i=0; i <= 7; i++){
pinMode(led[i], OUTPUT);
}
MsTimer2::set(1, clockIt);
MsTimer2::start();
digitalWrite(RESET, LOW);
}
void loop(){
// Serial.println(clockCount, DEC);
// delay(100);
updateFrame();
}
// Generates an animated patern
void updateFrame(){
for (char i=9; i >= 0; i--){
frame[i] = 0xFF, BYTE;
delay(100);
}
delay(100);
for (char i=0; i <= 9; i++){
frame[i] = 0x00, BYTE;
delay(100);
}
delay(100);
char horiz = 0x01;
for (char i=0; i <= 6; i++){
for (char i=0; i <= 9; i++){
frame[i] = horiz;
}
delay(100);
horiz = horiz << 1;
}
for (char i=0; i <= 7; i++){
for (char i=0; i <= 9; i++){
frame[i] = horiz;
}
delay(100);
horiz = horiz >> 1;
}
delay(100);
for (char i=0; i <= 9; i++){
frame[i] = 0x00, BYTE;
delay(100);
}
delay(100);
}
// Clocks the 4017 and switch the LEDs
void clockIt(){
if(clockCount < 9){
clockCount ++;
digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);
}
else{
clockCount = 0;
digitalWrite(CLOCK, HIGH); // The issue occurs wether I clock + reset, or just reset
digitalWrite(RESET, HIGH);
digitalWrite(CLOCK, LOW);
digitalWrite(RESET, LOW);
}
for (char i=0; i <= 7; i++){
digitalWrite(led[i], bitRead(frame[clockCount], i));
}
}