Controlling motor direction, usage and speed
You could achieve your goal combining a microcontroller with an H-bridge.

An H-bridge is a circuit that lets you control a motor, making it spin in both directions depending on commands given by a microcontroller. Here's an example of an H-Bridge built with BJTs.

You will then need to program your microcontroller with the exact pattern that you want, following the pseudo-code that you laid out in your question. If you are new to microcontrollers as you mentioned, I suggest you get started with an Arduino.

I hope this helps.