help with "tix led diy"!!!

Hi!!! This is my first post here, and i’m for ask help about a tix led
(if some one don’t know, it’s a clock very cool!!!) made from arduino
and some leds… now i’d like to implement an rtc like ds1302 or ds1307 (what
the difference!?) for the timekeeping every time i turn off and on…
how can i do?!!? This is the sketch

#include <DateTime.h>
#include <DateTimeStrings.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by
unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message

int colpins = {2,3,4,5,6,7,8,9,10};
int rowpins = {12, 11, 13};
char top;
long timer;
const long muxInterval = 20;
int mux = 0;
int x;
int timesync;
int hourlist2[3];
int hourlist[9];
int minlist2[6];
int minlist[9];
int oldminute;

void setup() {
Serial.begin(19200);
for (int pin=0; pin<9; pin++) {
pinMode( colpins[pin], OUTPUT );
}
for (int pin=0; pin<3; pin++) {
pinMode( rowpins[pin], OUTPUT );
}
DateTime.sync(DateTime.makeTime(0, 34, 12, 10, 4, 2010));;

}

/* void hoursplit(){
*/

void loop(){
int hour = (DateTime.Hour);
int minute = (DateTime.Minute);
int seconds = (DateTime.Second);
int newhour = 0;

if (seconds == 0 || timesync == 1) {
Serial.println(seconds);
// reset
for (int i = 0; i < 9; i++){
minlist = 0;
_ hourlist = 0;_
* }*
* for (int i = 0; i < 6; i++) {*
_ minlist2 = 0;
* }
for (int i = 0; i < 3; i++) {
hourlist2 = 0;
}
//math*

* //------------- start new code ---- july 22 2010 —
if (hour == hour){
// if (hour > 12){
// newhour = hour - 12;
// }
// if (hour < 12) {
// newhour = hour;
// }
// if (newhour == newhour){
// if (newhour == 0) {
// hourlist2[0] = 1;
// hourlist[0] = 1;
// hourlist[1] = 1;
// }
// if (newhour == 12){
// hourlist2[0] = 1;
// hourlist[0] = 1;
// hourlist[1] = 1;
// }
// if (newhour == 11){
// hourlist2[0] = 1;
// hourlist[0] = 1;
// }
// if (newhour == 10){
// hourlist2[0] = 1;
// hourlist2[1] = 0;
// hourlist2[2] = 0;
// for (int i = 0; i < 9; i++){
// hourlist = 0;
// }
// }
if (hour > 19 && hour < 24) {
hourlist2[0] = 1;
hourlist2[1] = 1;
int subhour = hour - 20;
for (int i = 0; i < subhour; i++){
hourlist = 1;
}
}
if (hour > 9 && hour < 20) {
hourlist2[0] = 1;
int subhour = hour - 10;
for (int i = 0; i < subhour; i++){
hourlist = 1;
}
}
if (hour > 0 && hour < 10) {
for (int i = 0; i < hour; i++){
hourlist = 1;
}
}
if (hour == 0){
}
//--------------------end new code*

* if (minute >= 0 and minute < 10) {
minlist2[0] = 0;
minlist2[1] = 0;
minlist2[2] = 0;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 0;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 10 and minute < 20) {
minlist2[0] = 1;
minlist2[1] = 0;
minlist2[2] = 0;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 10;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 20 and minute < 30) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 0;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 20;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 30 and minute < 40) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 30;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 40 and minute < 50) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 1;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 40;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 50 and minute < 60) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 1;
minlist2[4] = 1;
minlist2[5] = 0;
minute -= 50;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
}
timesync = 0;
}
// Random function*

if (seconds == 0 || seconds == 5 || seconds == 10 || seconds == 15
|| seconds == 20 || seconds == 25 || seconds == 30 || seconds == 35
|| seconds == 40 || seconds == 45 || seconds == 50 || seconds == 55)
{
* if (x == 1){
x = 0;
for (int a=0; a<9; a++){
int r = random(a,9);
int temp = minlist[a];
minlist[a] = minlist[r];
minlist[r] = temp;
}
for (int a=0; a<9; a++){
int r = random(a,9);
int temp = hourlist[a];
hourlist[a] = hourlist[r];
hourlist[r] = temp;
}
for (int a=0; a<6; a++){
int r = random(a,6);
int temp = minlist2[a];
minlist2[a] = minlist2[r];
minlist2[r] = temp;
}
for (int a=0; a<3; a++){
int r = random(a,3);
int temp = hourlist2[a];
hourlist2[a] = hourlist2[r];
hourlist2[r] = temp;
}
}
}
// random off for 10 seconds*

if (seconds == 1 || seconds == 6 || seconds == 11 || seconds == 16 ||
seconds == 21 || seconds == 26 || seconds == 31 || seconds == 36 ||
seconds == 41 || seconds == 46 || seconds == 51 || seconds == 56){
* x = 1;
}
// draw*

int rowone[] = {hourlist2[0], hourlist[0], hourlist[1], hourlist[2],
minlist2[0], minlist2[1], minlist[0], minlist[1], minlist[2]};
int rowtwo[] = {hourlist2[1], hourlist[3], hourlist[4], hourlist[5],
minlist2[2], minlist2[3], minlist[3], minlist[4], minlist[5]};
int rowthree[] = {hourlist2[2], hourlist[6], hourlist[7], hourlist[8],
minlist2[4], minlist2[5], minlist[6], minlist[7], minlist[8]};
if (millis() - timer < muxInterval)
* {
timer = millis();
mux++;
if (mux > 2){
mux = 0;
}
for (int i = 0; i <=8; i++){
digitalWrite(colpins, LOW);
}
digitalWrite(rowpins[0], LOW);
digitalWrite(rowpins[1], LOW);
digitalWrite(rowpins[2], LOW);
if (mux == 0) {
for (int i = 8; i >= 0; i–) {
if (rowone == 1){
digitalWrite(colpins, HIGH);
digitalWrite(rowpins[0], HIGH);
}
}
}
if (mux == 1) {
for (int i = 8; i >= 0; i–) {
if (rowthree == 1){
digitalWrite(colpins, HIGH);
digitalWrite(rowpins[2], HIGH);
}
}
}
if (mux == 2) {
for (int i = 8; i >= 0; i–) {
if (rowtwo == 1){
digitalWrite(colpins, HIGH);
digitalWrite(rowpins[1], HIGH);
}
}
}
}
// Time*

unsigned long prevtime;
* if( getPCtime()) { // try to get time sync from pc*
* Serial.print("Clock synced at: ");
Serial.println(DateTime.now(),DEC);
}
if(DateTime.available()) { // update clocks if time has been synced*

* digitalWrite(13,LOW); // first flash the LED*
* prevtime = DateTime.now();
DateTime.available(); //refresh the Date and time properties*

* }
}
boolean getPCtime() {
// if time sync available from serial port, update time and return*

true
* while(Serial.available() >= TIME_MSG_LEN ){ // time message*
consists of a header and ten ascii digits
* if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){*

* char c= Serial.read();
top = c;
if( c >= ‘0’ && c <= ‘9’){
pctime = (10 * pctime) + (c - ‘0’) ; // convert digits to a_

number
_ }
}
timesync = 1;
DateTime.sync(pctime); // Sync Arduino clock to the time*

received on the serial port
* return true; // return true if time message received on the*
serial port
* }
}
return false; //if no message return false*

}
ps a very big thanks to Dave Johnson for his original code!!! if
you want some photos, i’ll be very happy to send!!_

how can i do?

How can you do what?

You posted some code, but didn't say whether it worked for you, or not. Did it? If not, what doesn't work?

You said you want to implement an RTC "for the timekeeping every time i turn off and on". Do you have one? Do you know how to connect it? Every time you turn what off and on?

Hi, thanks for your reply, and escuse me for the bad question... i have a ds1302, and i'd like to connect (i know how) to this clock for keeping time every time i turn off and on the clock!!! I don't know how can i modify the original sketch for comunicate with ds and sync the time!

http://www.arduino.cc/playground/Code/Time
This library contains sample sketches. One of them gets the time from an RTC (a DS1307). Try it with the DS1302 and see if it works.

ds1302 or ds1307…difference

DS1307 has an I2C (two wore) interface; DS1302 has a simple 3-wire interface (more pins but simpler software). See Footnote.

have a ds1302[/quote]Posters can (sometimes) save bandwidth by giving complete information when they start asking for help.
For the DS1302, I started with the library from here: http://github.com/msparks/arduino-ds1302
Regards,
Dave
Footnote:
You can get data sheets for the ICs at http://www.maxim-ic.com/

I'm already able to use a ds1302 for write and read time, my problem it's "only" to find the way to integrate the code for rtc with my code!!

Otherwise, if it's possible, could be used a push button for increase the speed of time, until you reach the desired time... then unpress the button and the time return to flow normally.... i need some help becouse this sketch (at least the part of count time) it's too hard for my actual skills... thanks!!

Clock completed!!! With big help of uwefed, now this clock work with ds1302 for timekeeping!!! Here the code

#include <stdio.h>
#include <string.h>
#include <DS1302.h>
//#include <DateTime.h>
//#include <DateTimeStrings.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message

uint8_t CE_PIN = 14;
uint8_t IO_PIN = 15;
uint8_t SCLK_PIN = 16;
int colpins = {2,3,4,5,6,7,8,9,10};
int rowpins = {12, 11, 13};
char buf[50];
char day[10];
char top;
long timer;
const long muxInterval = 20;
int mux = 0;
int x;
int timesync;
int hourlist2[3];
int hourlist[9];
int minlist2[6];
int minlist[9];
int oldminute;

DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN); //definisce pin per collegamento RTC
/*
void print_time()
{
// Get the current time and date from the chip
Time t = rtc.time();
snprintf(buf, sizeof(buf), “%s %02d-%02d-%04d %02d:%02d:%02d”, // estrae i diversi valori dalla stringa del che il RTC da.
day,
t.date, t.mon, t.yr,
t.hr, t.min, t.sec);
}
*/
void setup() {
Serial.begin(19200);

for (int pin=0; pin<9; pin++) {
pinMode( colpins[pin], OUTPUT );
}
for (int pin=0; pin<3; pin++) {
pinMode( rowpins[pin], OUTPUT );
}
/* setta l orologio RTC
rtc.write_protect(false);
rtc.halt(false);
Time t(3, 5, 19, 2010, 21, 16, 37);

rtc.time(t);
*/
}

void loop(){

Time t = rtc.time(); //prende l’ ora dal RTC
int hour = t.hr;
int minute = t.min;
int seconds = t.sec;
int newhour = 0;

if (seconds == 0 || timesync == 1) {
Serial.println(seconds);
// reset
for (int i = 0; i < 9; i++){
minlist = 0;
_ hourlist = 0;_
* }*
* for (int i = 0; i < 6; i++) {*
_ minlist2 = 0;
* }
for (int i = 0; i < 3; i++) {
hourlist2 = 0;
} *_

* if (hour > 19 && hour < 24) {*
* hourlist2[0] = 1;*
* hourlist2[1] = 1;*

* int subhour = hour - 20;*
* for (int i = 0; i < subhour; i++){*
_ hourlist = 1;
* }
}
if (hour > 9 && hour < 20) {
hourlist2[0] = 1;
int subhour = hour - 10;
for (int i = 0; i < subhour; i++){
hourlist = 1;
}
}*_

* if (hour > 0 && hour < 10) {*
* for (int i = 0; i < hour; i++){*
_ hourlist = 1;
* }
}
if (hour == 0){
}*_

//--------------------end new code
* if (minute >= 0 and minute < 10) {*
* minlist2[0] = 0;*
* minlist2[1] = 0;*
* minlist2[2] = 0;*
* minlist2[3] = 0;*
* minlist2[4] = 0;*
* minlist2[5] = 0;*
* minute -= 0;*
* for (int i = 0; i < minute; i++){*
_ minlist = 1;
* }
}
if (minute >= 10 and minute < 20) {
minlist2[0] = 1;
minlist2[1] = 0;
minlist2[2] = 0;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 10;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 20 and minute < 30) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 0;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 20;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 30 and minute < 40) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 0;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 30;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 40 and minute < 50) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 1;
minlist2[4] = 0;
minlist2[5] = 0;
minute -= 40;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
if (minute >= 50 and minute < 60) {
minlist2[0] = 1;
minlist2[1] = 1;
minlist2[2] = 1;
minlist2[3] = 1;
minlist2[4] = 1;
minlist2[5] = 0;
minute -= 50;
for (int i = 0; i < minute; i++){
minlist = 1;
}
}
}*

timesync = 0;_

// Random function
if ((seconds == 0) || (seconds == 5) || (seconds == 10) || (seconds == 15) || (seconds == 20) || (seconds == 25) || (seconds == 30) || (seconds == 35) || (seconds == 40) || (seconds == 45) || (seconds == 50) || (seconds == 55))
{
if (x == 1){
* x = 0;*
* for (int a=0; a<9; a++){*
* int r = random(a,9);*
* int temp = minlist[a];*
* minlist[a] = minlist[r];*
* minlist[r] = temp;*

* }*
* for (int a=0; a<9; a++){*
* int r = random(a,9);*
* int temp = hourlist[a];*
* hourlist[a] = hourlist[r];*
* hourlist[r] = temp;*
* }*
* for (int a=0; a<6; a++){*
* int r = random(a,6);*
* int temp = minlist2[a];*
* minlist2[a] = minlist2[r];*
* minlist2[r] = temp;*
* }*
* for (int a=0; a<3; a++){*
* int r = random(a,3);*
* int temp = hourlist2[a];*
* hourlist2[a] = hourlist2[r];*
* hourlist2[r] = temp;*
* }*
}
}
// random off for 10 seconds
if (seconds == 1 || seconds == 6 || seconds == 11 || seconds == 16 || seconds == 21 || seconds == 26 || seconds == 31 || seconds == 36 || seconds == 41 || seconds == 46 || seconds == 51 || seconds == 56){
x = 1;
}

// draw

int rowone[] = {hourlist2[0], hourlist[0], hourlist[1], hourlist[2], minlist2[0], minlist2[1], minlist[0], minlist[1], minlist[2]};
int rowtwo[] = {hourlist2[1], hourlist[3], hourlist[4], hourlist[5], minlist2[2], minlist2[3], minlist[3], minlist[4], minlist[5]};
int rowthree[] = {hourlist2[2], hourlist[6], hourlist[7], hourlist[8], minlist2[4], minlist2[5], minlist[6], minlist[7], minlist[8]};

if (millis() - timer < muxInterval)
{
* timer = millis();*
* mux++;*
* if (mux > 2){*
* mux = 0;*
* }*
* for (int i = 0; i <=8; i++){*
_ digitalWrite(colpins*, LOW);*_

* }*
* digitalWrite(rowpins[0], LOW);*
* digitalWrite(rowpins[1], LOW);*
* digitalWrite(rowpins[2], LOW);*

* if (mux == 0) {*
* for (int i = 8; i >= 0; i–) {*
_ if (rowone == 1){
digitalWrite(colpins*, HIGH);
digitalWrite(rowpins[0], HIGH);
}
}
}*_

if (mux == 1) {
* for (int i = 8; i >= 0; i–) {*
_ if (rowthree == 1){
digitalWrite(colpins*, HIGH);
digitalWrite(rowpins[2], HIGH);
}
}
}*_

if (mux == 2) {
* for (int i = 8; i >= 0; i–) {*
_ if (rowtwo == 1){
digitalWrite(colpins*, HIGH);
digitalWrite(rowpins[1], HIGH);
}
}
}
}*_

// Time
/*
unsigned long prevtime;
if( getPCtime()) { // try to get time sync from pc
* Serial.print("Clock synced at: ");*
* Serial.println(DateTime.now(),DEC);*
}
if(DateTime.available()) { // update clocks if time has been synced
* digitalWrite(13,LOW); // first flash the LED*
* prevtime = DateTime.now();*

* DateTime.available(); //refresh the Date and time properties*
}
}
*/
/*
boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
* if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
_ char c= Serial.read();
top = c;
if( c >= ‘0’ && c <= ‘9’){
pctime = (10 * pctime) + (c - ‘0’) ; // convert digits to a number
}
}
timesync = 1;
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port*

* return true; // return true if time message received on the serial port*
* }
}
return false; //if no message return false
/

}_