Saturday, June 23, 2007
Yea, ok, I'm a geek. I'm an old geek. I like analog clocks, but my favorite one kept loosing time on occasion. So I scrounged an unused analog clock with a quartz movement from around the house to experiment on, pulled out the tools and performed a bit of surgery. I disconnected the drive coil from the rest of the circuit and soldered 2 wires on to it, put it back together and called the surgery a success. Then added a trimpot resistor inline with one of the wires, and connected them up to the parallel port to D0 and D1 / pin 2 and pin 3. The trimpot is a 5k resistor, but is currently set to around 600 ohms.
I connected this up to my linux machines' parallel port. The following python code is
what I'm currently running with. It needs to be run under root to access the /dev/port device correctly.
Happy Hacking, Toby Lane.
When starting this program, the clock hand positions can be given, e.g.
> clock 4 45 33
which tells the program that the clock hour hand is at 4, the minute is at 45, and the second is pointing to 33. The program will speed up or wait for the system clock and the analog clock to come together.
import time, os, sys
if len(sys.argv) > 1:
clock = int(sys.argv) * 3600 + int(sys.argv)*60 + int(sys.argv)
clock = int( open("/root/clock").readline().strip() )
clock = 0
wait = 0.97
if direction: d = b2
else: d = b1
direction = 1-direction
time.sleep( 0.0350 )
clock += 1
if clock >= 46800: clock = 3600
cur = list(time.localtime()[3:6])
if cur > 12: cur-=12
if cur < 1: cur += 12
cur = cur* 3600 + cur*60 + cur
dif = cur - clock
# print "clock",clock," cur",cur," dif",dif, " wait",wait
if dif < -5: time.sleep(5)
elif dif < -1: time.sleep(2)
elif dif == -1:
wait = min( 2, wait+0.001)
elif dif == 0: time.sleep(wait)
elif dif == 1:
wait = max( 0.5, wait-0.001 )
elif dif > 1: time.sleep(0.4)
open("/root/clock","w").write( "%s\n"%clock )