Pages: 1 [2]   Go Down
Author Topic: Domino Clock  (Read 9148 times)
0 Members and 1 Guest are viewing this topic.
The Hague, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Son Bitch!!!
With my thoughts of 30 minutes ago: this can't be so hard I finally figured it out:
Code:
   digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 0);   //Last Register
    shiftOut(dataPin, clockPin, MSBFIRST, 0);   //Second register
    shiftOut(dataPin, clockPin, MSBFIRST, 1);  //First Register
    digitalWrite(latchPin, HIGH);
And thats it, maybe some already knew but this was my eureka moment smiley
Anyways I visualised the chain of registers as a tube that you fill with marbles. You gotta start with the marbles (bits) that you want at the end of the chain and finish with the ones you want on top.
So hereby an explaination just in case other semi-retarded people like me don't get this problem.
hahaha
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27146
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In this part
2 >> 8

2 is supposed to be the name of a 16-bit variable (something that is type 'int').
Then you shift out twice:
shiftOut(dataPin, clockPin, MSBFIRST, minutes); // 1 numeral of minutes goes out
shiftOut(dataPin, clockPin, MSBFIRST, (minutes>>smiley-cool); // 2nd numeral of minutes goes out

assuming you had previously converted the minutes into two 8 bit pieces to go out to the individual dots on the minutes dominos.

Can you post the hardware schematic you have hooked up? I think I am getting myself confused,
you are using the time library which stores 2 numbers, hours & minutes, that you are then mapping to the domino dots?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

The Hague, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm i sort of get that but I finally worked out the code a bit:
This is at least with the way I figured it out, probably still not very efficient but better than the old "seperate definition for every minute of the hour"
Code:
#include <Time.h>


//Data Lines to the hour stone
int hlatchPin = 3;
int hclockPin = 4;
int hdataPin = 5;

//Data Lines to the decimal minute stone
int dlatchPin = 6;
int dclockPin = 7;
int ddataPin = 8;

//Data Lines to the single minute stone
int mlatchPin = 9;
int mclockPin = 10;
int mdataPin = 11;

int h = 0;
int m = 0;
int mins = 0;
int d = 0;
int previousHours = 0;
int previousMins = 0;

//I found it easiest to make a seperate data array for each shift register
byte dataArray1[12];
byte dataArray2[12];
byte dataArray3[12];



void setup() {

  pinMode(hlatchPin, OUTPUT);
  pinMode(hclockPin, OUTPUT);
  pinMode(hdataPin, OUTPUT);
  
  pinMode(dlatchPin, OUTPUT);
  pinMode(dclockPin, OUTPUT);
  pinMode(ddataPin, OUTPUT);
  
  pinMode(mlatchPin, OUTPUT);
  pinMode(mclockPin, OUTPUT);
  pinMode(mdataPin, OUTPUT);

  dataArray1[1] = 0;         dataArray2[1] = 0;      dataArray3[1] = 0;    
  dataArray1[2] = 0;         dataArray2[2] = 0;      dataArray3[2] = 0;      
  dataArray1[3] = 0;         dataArray2[3] = 0;      dataArray3[3] = 0;      
  dataArray1[4] = 0;         dataArray2[4] = 0;      dataArray3[4] = 0;      
  dataArray1[5] = 0;         dataArray2[5] = 0;      dataArray3[5] = 0;      
  dataArray1[6] = 0;         dataArray2[6] = 0;      dataArray3[6] = 0;      
  dataArray1[7] = 0;         dataArray2[7] = 0;      dataArray3[7] = 0;      
  dataArray1[8] = 0;         dataArray2[8] = 0;      dataArray3[8] = 0;      
  dataArray1[9] = 0;         dataArray2[9] = 0;      dataArray3[9] = 0;      
  dataArray1[10] = 0;        dataArray2[10] = 0;     dataArray3[10] = 0;
  dataArray1[11] = 0;        dataArray2[11] = 0;     dataArray3[11] = 0;
  dataArray1[12] = 0;        dataArray2[12] = 0;     dataArray3[12] = 0;

}

void loop() {
  
    h = hourFormat12();
    m = minute();

    if(previousHours != h) {
      digitalWrite(hlatchPin, LOW);
      shiftOut(hdataPin, hclockPin, MSBFIRST, dataArray1[h]);
      shiftOut(hdataPin, hclockPin, MSBFIRST, dataArray2[h]);
      shiftOut(hdataPin, hclockPin, MSBFIRST, dataArray3[h]);
      digitalWrite(hlatchPin, HIGH);
      previousHours = h;
    }
    if(previousMins != m) {  
      mins = m;
      if(mins >= 10) {
        d = 0;
        while(mins >= 10) {
          mins = mins - 10;
          d = d + 1;
        }
        digitalWrite(dlatchPin, LOW);
        shiftOut(ddataPin, dclockPin, MSBFIRST, dataArray1[d]);
        shiftOut(ddataPin, dclockPin, MSBFIRST, dataArray2[d]);
        shiftOut(ddataPin, dclockPin, MSBFIRST, dataArray3[d]);
        digitalWrite(dlatchPin, HIGH);
        digitalWrite(mlatchPin, LOW);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray1[mins]);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray2[mins]);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray2[mins]);
        digitalWrite(mlatchPin, HIGH);        
      }
      else {
        digitalWrite(dlatchPin, LOW);
        shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
        shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
        shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
        digitalWrite(dlatchPin, HIGH);
        digitalWrite(mlatchPin, LOW);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray1[mins]);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray2[mins]);
        shiftOut(mdataPin, mclockPin, MSBFIRST, dataArray3[mins]);
        digitalWrite(mlatchPin, HIGH);
      }
      previousMins = m;
    }

}

The hardware hookup i have to draw together as I did most on the go. The pin out from the shift registers i got to figure out because the wiring is a mess smiley
But to keep it short:
Each stone has its own dedicated data, clock and latch pin. And contains 3 shift registers.
Anyways ill post the circuit this afternoon / evening / some time soon.
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27146
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I can follow that nicely!

One question - for the minutes, where the display is only 0-5 & 0-9, you could probably get by with smaller arrays.

Ah - just occurred to me - you probably have double-six as the domino acting as the display, so you need 12. Can't seem to scroll back to the original post while I reply, will have to go look at that again.

Anyway, now that you have a seperate variable for each digit, I don't think you have to worry about the >> as you don't have the shift registers tied together serially.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27146
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I envision this as your setup. You will need 2 shiftouts per digit, so the >> will come into play anyway.
Hours:
Flesh this out, I think you're basically there, just need the mapping in the array to go out to the LEDs
Code:
int hours_display[13];
number_to_display[0] =   B0000000000000000; // not used, convenient to have 1-12 = 1-12 later
number_t0_display[1] =  B0000000001000000;
number_to_display[2] =  B0100000001000000;
:
:
number_to_display[12] = B0011111100111111;
/* format for shifting out
// shift out highbyte
shiftOut(dataPin, clock, MSBFIRST, (data >> 8));  
// shift out lowbyte
shiftOut(data, clock, MSBFIRST, data);
*/
//hours
digitalWrite(hlatchPin, LOW);
shiftOut(hdataPin, hclockPin, MSBFIRST, (number_to_display[h] >>8));
shiftOut(hdataPin, hclockPin, MSBFIRST, hours_display[h]);
digitalWrite(hlatchPin, HIGH);
:
:
// upper minutes digit
digitalWrite(dlatchPin, LOW);
shiftOut(ddataPin, dclockPin, MSBFIRST, (number_to_display[d] >> 8));
shiftOut(ddataPin, dclockPin, MSBFIRST, number_to_display[d]);
digitalWrite(dlatchPin, HIGH);
// lower minutes digit
digitalWrite(mlatchPin, LOW);
shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8));
shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);
digitalWrite(mlatchPin, HIGH);
:
:

« Last Edit: January 23, 2011, 01:23:40 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

The Hague, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,
Thanks for all the help I just reverse engineered the wiring on my board. Just have to make the arrays and then should be just about done.
And I actually put 18 LEDs in each stone
(please excuse my horrible text drawing skills)
[---------]
[  *  *  *  ]
[  *  *  *  ]
[  *  *  *  ]
[---------]
[  *  *  *  ]
[  *  *  *  ]
[  *  *  *  ]
[---------]

Anyways I put 18 LEDs in so I can also reprogram it to use as a basic text display.
Ill post more update stuff tomorrow!!
« Last Edit: January 23, 2011, 01:52:17 pm by SpencerH » Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27146
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ooh, forward thinking, I like that!
Makes the shift circuit a little bigger, need 3 per display instead of 2, shouldn't a big deal.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: 1 [2]   Go Up
Jump to: