Go Down

Topic: arduino Tix Clock (Read 1 time) previous topic - next topic

SilverCG

ever since I found this http://www.thinkgeek.com/interests/moms/7437/ i've always wanted one.

last year I made a python program that ran the graphics.py library and used it on my desktop.. now that I have an arduino I wanted to make a physical one..

so I wrote all the code by hand except for the time funtions. so it's very messy I haven't had the time to clean it up and i'm sure I've made a few.........a lot of progaming sins. so feel free to pick it apart and make fun of me..  ;D  it takes alot to hurt my feelings.

big thanks to raron for his help with the random function.

the clock stays surprisingly accurate I had it run for two days straight and it's not one second off.  the multiplexing was tricky I couldn't understand other peoples code so i tried to make my own based on what i understood on how it works. so some how it works it may not be the right way but it works.






Code: [Select]
#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[] = {13, 9, 8, 7, 6, 5, 4, 3, 2,};
int rowpins[] = {12, 11, 10};
float ms = .2;
char top;


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, 8, 11, 10, 4, 2010));;

 }

/* void hoursplit(){
 */
int x;
int hourlist2[3];
int hourlist[9];
int minlist2[6];
int minlist[9];
int oldminute;
void loop(){

delay (ms);
 

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

if (seconds == 0) {
Serial.println(seconds);
  // reset
 for (int i = 0; i < 9; i++){
 minlist[i] = 0;
 hourlist[i] = 0;
}
 for (int i = 0; i < 6; i++) {
   minlist2[i] = 0;
 }
 for (int i = 0; i < 3; i++) {
   hourlist2[i] = 0;
 }  
 
 
  //math
 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[i] = 0;
   }
 }
 if (newhour > 0 && newhour < 10) {
   for (int i = 0; i < newhour; i++){
     hourlist[i] = 1;
   }
 }

  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[i] = 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[i] = 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[i] = 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[i] = 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[i] = 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[i] = 1;
   }
 }
 
}
}
if (seconds == 0 || seconds ==  15 || seconds == 30 || seconds == 45){
 if (x == 1){
 
    x = 0;
for (int a=0; a<9; a++)
{
 int r = random(a,9); // dont remember syntax just now, random from a to 8 included.
 int temp = minlist[a];
 minlist[a] = minlist[r];
 minlist[r] = temp;

}
for (int a=0; a<9; a++)
{
 int r = random(a,9); // dont remember syntax just now, random from a to 8 included.
 int temp = hourlist[a];
 hourlist[a] = hourlist[r];
 hourlist[r] = temp;

}
for (int a=0; a<6; a++)
{
 int r = random(a,6); // dont remember syntax just now, random from a to 8 included.
 int temp = minlist2[a];
 minlist2[a] = minlist2[r];
 minlist2[r] = temp;

}
for (int a=0; a<3; a++)
{
 int r = random(a,3); // dont remember syntax just now, random from a to 8 included.
 int temp = hourlist2[a];
 hourlist2[a] = hourlist2[r];
 hourlist2[r] = temp;

}

}
}
if (seconds == 1 || seconds ==  16 || seconds == 31 || seconds == 46){
 
 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]};
delay(ms);
 for (int i = 8; i >= 0; i--) {
   if (rowone[i] == 1){
     digitalWrite(colpins[i], HIGH);
     digitalWrite(rowpins[0], HIGH);
   }
     
 }
 delay(ms);
 for (int i = 8; i >= 0; i--) {
     digitalWrite(colpins[i], LOW);
     digitalWrite(rowpins[0], LOW);  
 }
 delay(ms);
 
 for (int i = 8; i >= 0; i--) {
   if (rowthree[i] == 1){
     digitalWrite(colpins[i], HIGH);
     digitalWrite(rowpins[2], HIGH);
   }
     
 }
 delay(ms);
 for (int i = 8; i >= 0; i--) {
     digitalWrite(colpins[i], LOW);
     digitalWrite(rowpins[2], LOW);  
 }
 delay(ms);
 
   for (int i = 8; i >= 0; i--) {
   if (rowtwo[i] == 1){
     digitalWrite(colpins[i], HIGH);
     digitalWrite(rowpins[1], HIGH);
   }
     
 }
 delay(ms);
 for (int i = 8; i >= 0; i--) {
     digitalWrite(colpins[i], LOW);
     digitalWrite(rowpins[1], LOW);  
 }
 delay(ms);
 
 

// 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    
       }
     }
       
     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
}




Cheers,
Dave Johnson

SilverCG

forgot to mention that i'm planning on getting a wwvb receiver and sync it to the atomic clock.

nytro81

Hi, great work! I ever loved the tix led, and now i want to try with your code!!! Can you tell me or send a pm about the led connection? Thanks!!

artjumble

This is very cool. Kind of like a binary clock, but less binary.  :)

I am now considering building my own someday.

Adrastos

Nicely done!

I too have wanted one of these forever, and figured I could do one myself. Just need the time!

Do you have plans for a more permanent mounting (rather than breadboard)?

Go Up