How to get single passes through loop?

Again a long delay, while I got the hardware side working better... In addition, I did a bit of a rethink on this, and think I've come up with a better solution that will work for any time this sort of single pass thing is needed...

It has the advantage (I think, but haven't verified yet) that it will be easy to trim out once the development is done and you want to get to running the actual programs...

Essentially my new approach is rather than trying to stop the code while in the loop function, I have created a separate function that sits and loops until the "step" button is pushed, then returns to the main loop for one pass until it's called again at the end of the loop...

A first draft sketch - I've got some calls to the TLC library in it, but don't actually do anything with it - that's next... :cold_sweat:

I also have a lot of serial print functions to show it working, but will probably comment them out once I start doing other code.

const int buttonPin = 4; // N/O push button attached to any pin not otherwise needed
int buttonPush = 1;   // State of button - goes low when pushed, then returns to high
int buttonState = 0;         // current state of the button
int lastButtonState = 1;     // previous state of the button

// Use TLC library
#include "Tlc5940.h"

// Define number of chanels
const int chan_no = 24;

/////////////////////////////////////////////////////////

void setup() {

  // button SWITCH SETUP - NOTE switch ON = 0
  pinMode(buttonPin,INPUT);
  digitalWrite(buttonPin, HIGH);

  // initialize serial communication at 9600 bits per second 
  Serial.begin(9600);
  delay(1000);

  /* Call Tlc.init() to setup the tlc.
   You can optionally pass an initial PWM value 
   (0 - 4095) for all channels.*/
  Tlc.init();
}

// Direction - channel number increment / decrement selector.
// 1 increments, -1 decrements

// start w/ incrementing

int direction = 1;

///////////////////////////////////////////////

void loop() {    

  delay (10);
  Serial.print("In LOOP buttonState = ");
  Serial.println(buttonState);
  Serial.print("buttonPush = ");
  Serial.println(buttonPush); 
//////////////////////////////////////////////////////////////////
INSERT TEST CODE HERE!!!!  NOTE, function must be called as last step in any repeating loop!
////////////////////////////////////////////
  //Must read or define button variables in order for function test to reset  
  
  buttonState = digitalRead(buttonPin);
  buttonPush=HIGH;
  stopactFunction (); 
}

void stopactFunction () {

  delay (10);
  Serial.print("beginning of stopactFunction buttonState = ");
  Serial.println(buttonState); 
  Serial.print("buttonPush = ");
  Serial.println(buttonPush); 

  while (HIGH == buttonPush) {  //loop until buttonPush goes low
    delay (10);
    Serial.print("Waiting - buttonState = ");
    Serial.println(buttonState); 
    Serial.print("buttonPush = ");
    Serial.println(buttonPush); 

    delay (200);
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    // compare the buttonState to its previous state
    if (buttonState != lastButtonState) {
      // if the state has changed, check for button pushed or released
      if (buttonState == LOW) {
        // if the current state is LOW then the button
        // pushed: lower the state and break out of loop
        buttonPush = LOW;
      } 
      else {
        // if the current state is HIGH then the button
        // released, make sure the state stays high
        buttonPush = HIGH;   
      }
      lastButtonState = buttonState;
    }
  }
  return;

} // END stopactFunction