real life code saves fishes
Wednesday, April 30th, 2008Some time ago the time control light switch of my son’s aquarium died.
So far this hasn’t been a practical problem, because he simply took over the job of switching the light on in the morning and off in the evening.
Last week we prepared for a short vacation and realized that we didn’t get a replacement for the light switch in time. There was no hope from our neighbours since they were gone too. So what to do? Let the fishes in the dark and potentially die?
Lukily I had a spare mini-itx computer with linux installed and custom made TRIAC circuit at hand from disco light experiments some years ago.

The mini-itx machine had linux and python running on it. The triac circuit to function as a parallel port controled power switch was built using instructions from http://discolitez.com/circuits-8triac.shtml.
So the challenge was to write some reliable software that the life of my son’s fishes could depend on.
Unfortunately I couldn’t test the system in full extend, since we had to leave early the next morning.
I definitely didn’t feel that easy imagining that the fishes might die due to buggy code …
Lukily the coding problem wasn’t that complex.
I wrote some python code like:
import time
import parallel
p = parallel.Parallel()
while(1):
h = time.localtime()[3]
if h > 6 and h < 18:
p.setData(1)
else:
p.setData(0)
time.sleep(60)
And all went well.