Post #34, #36 cover this.

You could develop a more cunning solution with an Arduino at low cost.