improved timer: added millis() function

; implemented state machine