I think you could do this with an Arduino and a simple program.