Go Down

Topic: Domino Clock (Read 9 times) previous topic - next topic

CrossRoads

Ok, looks like we posted at similar times and you have something similar worked out already.
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.

SpencerH

Hehe alright.

But you think that my method of shifting out data works?

I have ordered all of the electronics parts so I'll be posting updates as I go along.

Oh does anyone have experience with the Time library? I based my code on the readme but am not sure if it's all correct.

CrossRoads

#7
Jan 17, 2011, 05:04 pm Last Edit: Jan 17, 2011, 05:25 pm by CrossRoads Reason: 1
No, the shifting out probable needs some adjusting.
Shiftout sends out one byte of data one bit at a time. If you are sending 3 bytes,
10110110 11011011 01000000  data array 12 for example you will need three shiftout commands

Modifying the shiftout example from 2 bytes to 3 would yield something like this:
Code: [Select]

// Do this for MSBFIRST serial
// replace 'data' with you array definition
// shift out highbyte
shiftOut(dataPin, clock, MSBFIRST, (data >> 8));  
// shift out middlebyte
shiftOut(data, clock, MSBFIRST, (data>>8));
// shift out lowbyte
shiftOut(data, clock, MSBFIRST, data8);


This part is reading some buttons? You will need some debounce to keep from getting multiple presses:
Code: [Select]

hourState = digitalRead(hourPin);
minState = digitalRead(minPin);

//Hour adjustment
if (hourState == HIGH) {
 time_t t = now();
 t = t + 3600;
 setTime(t);
}
//Minute adjustment
if (minState == HIGH) {
 time_t t = now();
 t = t + 60;
 setTime(t);
}


Why not simply the code for writing out the display? You are only updating once a minute and once an hour, right?
So keep track of when the minute changes or when the hour changes and then send out an update.
It looks like
if (hourFormat12() == 11)
&
if (minute() == 0)
do the time tracking for you.
Just sit in a loop, and when you detect a difference, then do the shiftout commands
Code: [Select]

ex. old_hours = 0;
old_minutes = 0;
new_hours = hourformat12();
new_minutes = minute();
if (new_hours != old_hours) {
// send out new hours
hours = dataArray[new_hours]
  digitalWrite(latchPin1, LOW);
 shiftOut(dataPin1, clockPin1, MSBFIRST, hours);
 digitalWrite(latchPin1, HIGH);
old_hours = new_hours;
}
if (new_minutes != old_minutes){
// do your math here to break up into tens_minutes & ones_minutes
//example
// high_digit = 0
// if (new_minutes <10) {high_digit = 0;  low_digit = new_minutes;}  // minutes is from 00 to 09
// while (new_minutes >=10 { // loop thru as needed and lop off 10 minutes at a time,
//     high_digit = high_digit+1;  // updating the high_digit for every 10 minutes
//     new_minutes = new_minutes -10;}
//     low_digit = new_minutes;  // when less than 10 is left, the balance is the low digit
//     }
//

tens_minutes = dataArray[high_digit];
ones_minutes = dataArray[low_digit];
 digitalWrite(latchPin2, LOW);
 digitalWrite(latchPin3, LOW);
 shiftOut(dataPin2, clockPin2, MSBFIRST, tens_minutes);
 shiftOut(dataPin3, clockPin3, MSBFIRST, one_minutes);
 digitalWrite(latchPin2, HIGH);
 digitalWrite(latchPin3, HIGH);
old_minutes = new_minutes;
}
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.

SpencerH

Cool I'll start adjusting the shiftout first and use that with the original code and as soon as thats working then ill try to implement some math to it.
Although it surprised me that the difference between shifting out the first and second byte is only a space.

shiftOut(dataPin, clock, MSBFIRST, (data[glow] [/glow]>>[glow] [/glow]8));  

shiftOut(data, clock, MSBFIRST, (data>>8));

CrossRoads

The spaces are ignored during compiling.
The " >>8" indicate the data is shifted by 8 places.
Might even need to be 16, then 8, then none.
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.

Go Up