How can I make the redstone repeat a task x times and reset it self?

As with most counting problems in Minecraft, the answer is eggs.

Take a look at my sample setup.

enter image description here

Redstone explanation

  1. To the right, we have a monostable circuit to shorten the input (the button) down to 1 tick. I use Sethbling's favored design, the repeater is set to 3.

  2. The Centerpiece is a Hopper-Dropper-Counter (a hopper and dropper pointing into each other), containing, in this case, 9 Eggs (or anything that stacks to 16) and 10 Cobblestone (or anything that stacks to 64), for a total of 19 items. You realize this is 1 short, but that's actually fine.

  3. The comparator turns to 3 when all items are in the hopper. In this case, the torch at the bottom of the picture turns off.

  4. The last component is a Repeater-Lock. On each button press, the hopper will update to whatever redstone signal is on the bottom torch before the button was pressed. So if it's at three bars after 19 clicks, it will unlock the hopper on the 20th click, causing all items to go back into the dropper.

To make something happen every 20th click, you should get the signal from the block next to the hopper (i.e. the state of the locked repeater), it is only ever off 1/20 of the time. You could put redstone dust underneath, or put a torch on top, for example (but watch out for signal inversion).


Design notice: I used a variation of this for a three state enchanting room (lvl 1, lvl 18, lvl 30 enchants), using 2 wooden swords, and repeaters checking for a signal >0 and >3, respectively.