Forum Index > Projects > Clock Kits
 Seconds hand display and code refactoring
 |  Printable Version
By: Anonymous: Robert () on Thursday, February 23 2012 @ 01:52 PM PST  
Anonymous: Robert

Quote by: Robert
First calculate:
((year − 2000) * 12) + (month) + 45
Now we have a sort of serial month number, in a system which counts March 1996 as month 0.



Sorry, that formula got mangled. It should be:

PHP Formatted Code
((year - 2000) * 12) + (month) + 45





       
   
By: brand (offline) on Sunday, March 11 2012 @ 11:30 AM PDT  
brand

Quote by: Robert

Hudson:

Calculation of the day of the week given this serial day number is left as an exercise for the reader.



Hint: See Zeller's congruence:
http://en.wikipedia.org/wiki/Zeller%27s_congruence


Forum Apprentice
Apprentice

Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Anonymous: Robert () on Sunday, March 11 2012 @ 05:18 PM PDT  
Anonymous: Robert

Quote by: brand

Quote by: Robert

Hudson:

Calculation of the day of the week given this serial day number is left as an exercise for the reader.



Hint: See Zeller's congruence:
http://en.wikipedia.org/wiki/Zeller%27s_congruence



That's like going from Boston to New York by way of Chicago.

Since you already have the serial day number, just do a modulo 7.
If you don't want 0 to stand for Friday, just add a constant before doing the modulo operation.





       
   
By: brand (offline) on Monday, March 12 2012 @ 08:09 AM PDT  
brand

Quote by: Robert


That's like going from Boston to New York by way of Chicago.


D'oh!

Right. I forgot that Zeller's congruence has the modulo operation in it as well. I'm always trying to avoid non-integer arithmetic....


Forum Apprentice
Apprentice

Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Anonymous: Robert () on Monday, March 12 2012 @ 02:23 PM PDT  
Anonymous: Robert

Quote by: brand

Quote by: Robert


That's like going from Boston to New York by way of Chicago.


D'oh!

Right. I forgot that Zeller's congruence has the modulo operation in it as well. I'm always trying to avoid non-integer arithmetic....



The modulo operation is integer arithmetic.

Do you mean, avoid division?

To do a "modulo 7" on x: (untested code)

PHP Formatted Code

x = (x >> 24) + (x & 0xFFFFFF);
x = (x >> 12) + (x & 0xFFF);
x = (x >> 6) + (x & 0x3F);
x = (x >> 3) + (x & 7);
while (x >= 7) x -= 7;
 





       
   



 All times are PDT. The time is now 03:41 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?