It could be easily done with a small microcontroller but you'd have to program it up. Something like a Digispark has more than enough horsepower, programs with Arduino code, tiny and fairly cheap . . . but the secret-sauce programming is the hard part.
If you've got a little bit of coding background, it would be an easy project. If you don't, then not so much.