Code component: wait for a number of frames?

Hi

I am having some timing issues with dropping frames in a very time sensitive experiment. Currently I have the time sensitive stimulus being shown for 2 frames at the very beginning of a routine, with a number of other polygons being drawn at the same time, which I suspect is causing some of the issues.
What I instead want to do is draw all the needed polygons earlier, and then display them at the appropriate time by changing their opacity, which I understand should be computationally faster (running off a 1650 gtx).
I am trying to display a stimulus for 2 frames on a key release, which is detected with:

if defaultKeyboard.getKeys(['down'], waitRelease=True):
    opacity = 1

What would I add to this to wait for 2 frames and then revert opacity to 0?

Hope this makes sense!

Anything you write in the Each Frame tab of a code component is run each frame, so I would make a variable counting how many frames pass. Something like

if defaultKeyboard.getKeys(['down'], waitRelease=True) and not counting:
    # If key is pressed and we're not already counting, start counting
    counting = True
    count = 0
    # Start showing stimulus
    opacity = 1

if counting:
    # Count +1 for this frame
    count += 1

if count >= 2:
    # When count hits limit, stop counting
    counting = False
    # Stop showing stimulus
    opacity = 0