Running a program only once per activation

I am new to programming in general and need help with a very simple task. I am running a motor and would like my task to be run on the push of a button but only repeat after it is pressed again. avoiding the user to be able to hold the button down and repeat the task. Thank you for your help. and please be simple with the lingo as I don't understand many technical terms.

Run your code only if a variable is set to true, then set the variable to false when the code is finished.
Set the variable to true when the button is pushed.

What @larryd said +
Pushbutton starts the task... What ends the task?

Push button, x = 0
If x = 0
Do code
At end of code, x = 1

Look at the StateChangeDetection example in the standard examples.

larryd:
Run your code only if a variable is set to true, then set the variable to false when the code is finished.
Set the variable to true when the button is pushed.

That was my first thought and I attempted this but it was unsuccessful. Could you possibly give a crude example

Why not post your unsuccessful attempt, and we can show you where it went wrong?

Always show us your current compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Nathanmsommer:
That was my first thought and I attempted this but it was unsuccessful. Could you possibly give a crude example

Something like this...

boolean buttonPushed;
boolean hasRun;

...

void loop()
{
  buttonPushed = !digitalRead (buttonPin) ; //Assume you use INPUT_PULLUP on buttonPin
  //delay(20);
  if (buttonPushed=true)
  {
    if (hasRun=false)
    {
     //Run your code here
     hasRun=true;
    }
  } else
  {
    hasRun=false;
  }
}

After your code is run, hasRun is set to true, ad your actual program isn't run again.
HasRun is reset to false only when your button is read as as not pushed.
If your code executes very quickly and the button bounce is detected as release and pushed again, uncomment the delay.

  if (buttonPushed=true)

?

Something like, not exactly like :grinning: