First project: LED clock
i joined forum , i'm right in first project. wanted built myself led clock. it's should simple clock show hours , minutes , in middle 2 leds blinking each second. here picture of it:
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_u8wGwYGOLOZEUErdRBp_JgG568yHdGqErbG0-VGSrZSeVa1VbecW3QDCVOWqJehO3jGlNyd9hFNStFpvISJ82uXL9_SqwoR6srfE_UAJTc4bk=s0-d)
i used arduino uno can detached clock , ds1307 unit. leds wired in 7x8 matrix 54 white leds. dont use driver led matrix wanted direct drive it.
here can find curcuit diagramm of said clock , how matrix wired.
the code in next post.
it might made more complicated has i'm not programmer want make way can understand it. gettime function takes time ds1307 unit, setmatrix says leds should turned on , showmatrix function multiplexing part. rest of code should self explanatory
.
thats problem is. works fine , shows time quite nice found out leds seem brigther others. intended multiplexing scans row after row seemed made mistake there , mutliplexing scans column after column. problem of differences in brightness of leds? problem in showmatrix function. how can change part row scanning?
i tried change ended more in mess. might small problem can't find solution. hope can me
.
thanks in advance
lukrab
i used arduino uno can detached clock , ds1307 unit. leds wired in 7x8 matrix 54 white leds. dont use driver led matrix wanted direct drive it.
here can find curcuit diagramm of said clock , how matrix wired.
the code in next post.
it might made more complicated has i'm not programmer want make way can understand it. gettime function takes time ds1307 unit, setmatrix says leds should turned on , showmatrix function multiplexing part. rest of code should self explanatory
![wink ;)](https://forum.arduino.cc/smileys/arduino/wink.gif)
thats problem is. works fine , shows time quite nice found out leds seem brigther others. intended multiplexing scans row after row seemed made mistake there , mutliplexing scans column after column. problem of differences in brightness of leds? problem in showmatrix function. how can change part row scanning?
i tried change ended more in mess. might small problem can't find solution. hope can me
![wink ;)](https://forum.arduino.cc/smileys/arduino/wink.gif)
thanks in advance
lukrab
had shorten code long. setmatrix function tells leds @ minute or hour should turn on.
code: [select]
#include "wire.h"
#define ds1307_i2c_address 0x68
byte second = 10; //set seconds 0-59
byte minute = 11; //set minutes 0-59
byte hour = 13; //set hours 0-23
int cols[7] = {5, 4, 3, 2, a1, a2, a3}; // connect columns of 8x6 led matrix these pins.
int rows[8] = {13, 12, 11, 10, 9, 8, 7, 6}; // connect rows of 8x6 led matrix 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 normal decimal numbers
return ( (val/16*10) + (val%16) );
}
byte dectobcd(byte val){ //convert normal decimal numbers binary coded decima
return ( (val/10*16) + (val%10) );
}
void setup(){
wire.begin();
//settime(second, minute, hour); //turn on once set time
for (int = 0; < 7; i++) { //set col-pins output
pinmode(cols[i], output);
}
for (int = 0; < 8; i++) { //set row-pins 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 bit 7 starts clock
wire.write(dectobcd(minute));
wire.write(dectobcd(hour));
wire.endtransmission();
}
void gettime(byte *second, byte *minute, byte *hour){ // gets date , time ds1307
wire.begintransmission(ds1307_i2c_address); // reset register pointer
wire.write(0);
wire.endtransmission();
wire.requestfrom(ds1307_i2c_address, 7);
*second = bcdtodec(wire.read() & 0x7f); // few of these need masks because bits control bits
*minute = bcdtodec(wire.read());
*hour = bcdtodec(wire.read() & 0x3f);
}
void setmatrix(){ //defines leds should turned on printmatrix
}
void showmatrix(){ // multiplexing led matrix
for (int y = 0; y < 7; y++) { // parse rows
for (int x = 0; x < 8; x++) { // set previous rows 0 , matrix value on corresponding pin
digitalwrite(rows[x], !matrix[x][y]);
}
digitalwrite(cols[y], 1); // set current col 1
delay(1);
digitalwrite(cols[y], 0); // delete current row
}
}
Arduino Forum > Using Arduino > Project Guidance > First project: LED clock
arduino
Comments
Post a Comment