First project: LED clock

I just joined this forum and I'm right in my first project. I wanted to built myself a LED clock. It's should be just a simple clock to show the hours and minutes and in the middle two leds blinking each second. Here is a picture of it:

I used a Arduino UNO which can be detached from the clock and a DS1307 unit. The LEDs are wired in a 7x8 matrix with 54 white LEDs. I dont use a driver for the LED matrix as I wanted to direct drive it.

Here you can find a curcuit diagramm of said clock and how the matrix is wired.

The code is in the next post.

It might look like I made it more complicated than it has to be but as I'm not a good programmer I want to make it the way I can understand it. Basically the getTime function takes the time from the DS1307 unit, the setMatrix says which LEDs should be turned on and the showMatrix function does the multiplexing part. The rest of the code should be self explanatory ;).

Thats where the problem is. It just works fine and shows the time quite nice but I found out that some LEDs seem brigther than others. I intended to do the multiplexing that scans row after row but it seemed that I just made a mistake there and the mutliplexing scans column after column. Could that be the problem of the differences in brightness of the LEDs? So the problem is in the showMatrix function. How can I change that part that I get the row scanning?

I tried to change it but it ended more in a mess. Might be a small problem but I can't get to find the solution. So I hope you can help me ;).

Thanks in advance
lukrab

Had to shorten the code as it was too long. The setMatrix function just tells the LEDs at which minute or hour it should turn on.

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68

byte second =      10; //set seconds from 0-59
byte minute =      11; //set minutes from 0-59
byte hour =        13; //set hours from 0-23

int cols[7] = {5, 4, 3, 2, A1, A2, A3}; // Connect the columns of the 8x6 led matrix to these pins.
int rows[8] = {13, 12, 11, 10, 9, 8, 7, 6}; // Connect the rows of the 8x6 led matrix to these pins.
int matrix[8][7] = {
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0},
  { 0, 0, 0, 0, 0, 0, 0}
};

byte bcdToDec(byte val){ //convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

byte decToBcd(byte val){ //convert normal decimal numbers to binary coded decima
  return ( (val/10*16) + (val%10) );
}


void setup(){
  Wire.begin();
  
  //setTime(second, minute, hour); //turn on once to set time
  
  for (int i = 0; i < 7; i++) { //set the col-pins too OUTPUT
    pinMode(cols[i], OUTPUT);
  }
  for (int i = 0; i < 8; i++) { //set the row-pins too OUTPUT
    pinMode(rows[i], OUTPUT);
  }
}


void loop(){
  getTime(&second, &minute, &hour);
  setMatrix();
  showMatrix();
}


void setTime(byte second, byte minute, byte hour){
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.write(0);
   Wire.write(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.write(decToBcd(minute));
   Wire.write(decToBcd(hour));    
   Wire.endTransmission();
}

void getTime(byte *second, byte *minute, byte *hour){ // Gets the date and time from the ds1307
  Wire.beginTransmission(DS1307_I2C_ADDRESS); // Reset the register pointer
  Wire.write(0);
  Wire.endTransmission();
  
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  
  *second     = bcdToDec(Wire.read() & 0x7f); // A few of these need masks because certain bits are control bits
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);
}

void setMatrix(){ //defines which leds should be turned on by printMatrix 
}

void showMatrix(){ // does the multiplexing for the LED matrix
  for (int y = 0; y < 7; y++) { // Parse all rows 
    for (int x = 0; x < 8; x++) { // Set previous rows to 0 and matrix value on the corresponding pin
      digitalWrite(rows[x], !matrix[x][y]);
    }
  digitalWrite(cols[y], 1); // Set current col to 1
  delay(1);
  digitalWrite(cols[y], 0); // Delete current row
  } 
}