Simple Cycle Counter

I have the arduino providing simple signals to operate a motor controller. I need a way to make it repeat the program at the end of this message a predetermined number of times (in this case, 3000 times) and then just stop. I’m sure it’s probably simple, but I just don’t know how. Thank you.

/*
 * Motor Controller
 * Purpose: apply the required signals to the motor control board of the 2 inch pt system
 * in order to control tilt cycle testing.  
 * It pulls the control pins to low for signal, holds them for specified time, then returns
 *them to high to stop the motor. It then waits for a specified time and repeats in the opposite
 *direction.  Byron Morgan 14May2009
 * 01JULY2009  BNMORGAN  MODIFIED FOR TESTING OF 1" PT
 * 23DEC2009 BNMORGAN MODIFIED FOR LONG DURATION TEST DURING CHRISTMAS BREAK FOR 1" PT
 */

int CCW = 12;              // Counterclockwise trigger to pin 12
int CW = 11;               // Clockwise trigger pin to Pin 11
int CWLED = 7;             // CW LED Indicator
int CCWLED = 6;            // CCW LED Indicator
int WAITLED = 5;           // WAIT LED Indicator

void setup()               // run once, when the sketch starts
{
  // sets the digital pins as output
  pinMode(CCW, OUTPUT);    //close front
  pinMode(CW, OUTPUT);     //close rear
  pinMode(CWLED, OUTPUT);  //yellow
  pinMode(CCWLED, OUTPUT); //green
  pinMode(WAITLED, OUTPUT);  //red
}

void loop()                // run over and over again

{
  // OVERALL RUNTIME 23DEC2009 IS 00:05:30 PER CYCLE
  digitalWrite(CCW, LOW);           // sets the CCW pin LOW to tell the board to run for ontime
  digitalWrite(WAITLED, LOW);
  digitalWrite(CCWLED, HIGH);
  delay(10000);                   // wait seconds = OnTimeCCW
  digitalWrite(CCW, HIGH);          // sets the CCW pin HIGH to tell the board to stop running
  digitalWrite(CCWLED, LOW);
  digitalWrite(WAITLED, HIGH);
  delay(40000);                     // wait seconds = offtime
  digitalWrite(CW, LOW);            // sets the CW pin LOW to tell the board run for ontime
  digitalWrite(CCWLED, LOW);
  digitalWrite(WAITLED, LOW);
  digitalWrite(CWLED, HIGH);
  delay(10000);                     // wait seconds = OnTimeCW
  digitalWrite(CW, HIGH);           // sets the CW pin HIGH to tell the board to stop running
  digitalWrite(CWLED, LOW);
  digitalWrite(WAITLED, HIGH);
  delay(240000);                     // wait seconds = offtime
}

If you want it to stop, put the code in "setup", which runs only once per reset.

My problem is that i don't know what to put to create a cycle counter nor make it stop when it reaches "X" cycles

#define CYCLE_TIMES 50000L
...
for (long i= 0; i < CYCLE_TIMES; ++i) {
 ///the stuff that needs to cycle here
}

I hate asking simple questions…coding isn’t something I’m very good at, and don’t do often so I loose some of what i learn between times.
Which place do i put the number of required cycles before stopping?
All this goes before void setup except the last } right? :-?moderately confused

#define CYCLE_TIMES 50000L (is this the max number limit)

for (long i= 0; i < CYCLE_TIMES; ++i) {
///the stuff that needs to cycle here
}

No worries - I re-read the initial post, so

#define CYCLE_TIMES 3000L

or

const long CYCLE_TIMES = 3000L;

And yes, all before the final "}" of setup.

Alternatively, put the "for" loop in "loop", and put a for (;;) {;} after the last } of the "for" loop.

I am getting a compile error, most likely a loose nut in the chair. I’ve got so much to learn >.<
Please verify, if it’s not too much to ask:

/*
 * Motor Controller
 * Purpose: apply the required signals to the motor control board of the 2 inch power tilt
 * in order to control tilt cycle testing.  
 * It pulls the control pins to low for signal, holds them for specified time, then returns
 *them to high to stop the motor. It then waits for a specified time and repeats in the opposite
 *direction.  Byron Morgan 14May2009
 * 01JULY2009  BNMORGAN  MODIFIED FOR TESTING OF 1" PT
 * 23DEC2009 BNMORGAN MODIFIED FOR LONG DURATION TEST DURING CHRISTMAS BREAK FOR 1" PT
 */

int CCW = 12;              // Counterclockwise trigger to pin 12
int CW = 11;               // Clockwise trigger pin to Pin 11
int CWLED = 7;             // CW LED Indicator
int CCWLED = 6;            // CCW LED Indicator
int WAITLED = 5;           // WAIT LED Indicator


void setup()               // run once, when the sketch starts
{
  // sets the digital pins as output
  pinMode(CCW, OUTPUT);    //close front
  pinMode(CW, OUTPUT);     //close rear
  pinMode(CWLED, OUTPUT);  //yellow
  pinMode(CCWLED, OUTPUT); //green
  pinMode(WAITLED, OUTPUT);  //red
  #define CYCLE_TIMES 3000L;   // number of cycles before halt
  
}


void loop()                // run over and over again

  // OVERALL RUNTIME 23DEC2009 IS 00:05:00 PER CYCLE
  for (long i= 0; i < CYCLE_TIMES; ++i) {  
  digitalWrite(CCW, LOW);           // sets the CCW pin LOW to tell the board to run for ontime
  digitalWrite(WAITLED, LOW);
  digitalWrite(CCWLED, HIGH);
  delay(5500);                   // wait seconds = OnTimeCCW, 5500 minimum
  digitalWrite(CCW, HIGH);          // sets the CCW pin HIGH to tell the board to stop running
  digitalWrite(CCWLED, LOW);
  digitalWrite(WAITLED, HIGH);
  delay(1000);                     // wait seconds = offtime
  digitalWrite(CW, LOW);            // sets the CW pin LOW to tell the board run for ontime
  digitalWrite(CCWLED, LOW);
  digitalWrite(WAITLED, LOW);
  digitalWrite(CWLED, HIGH);
  delay(5500);                     // wait seconds = OnTimeCW, 5500 minimum
  digitalWrite(CW, HIGH);           // sets the CW pin HIGH to tell the board to stop running
  digitalWrite(CWLED, LOW);
  digitalWrite(WAITLED, HIGH);
  delay(2000);                     // wait seconds = offtime
  }
  for {;;} {;}
}

You haven’t declared “CYCLE_TIMES”. Lose the “;” at the end. Add a “{” after “loop ()”
Put it up near the declaration of WAITLED, maybe?

/*
 * Motor Controller
 * Purpose: apply the required signals to the motor control board of the 2 inch power tilt
 * in order to control tilt cycle testing.  
 * It pulls the control pins to low for signal, holds them for specified time, then returns
 *them to high to stop the motor. It then waits for a specified time and repeats in the opposite
 *direction.  Byron Morgan 14May2009
 * 01JULY2009  BNMORGAN  MODIFIED FOR TESTING OF 1" PT
 * 23DEC2009 BNMORGAN MODIFIED FOR LONG DURATION TEST DURING CHRISTMAS BREAK FOR 1" PT
 */

int CCW = 12;              // Counterclockwise trigger to pin 12
int CW = 11;               // Clockwise trigger pin to Pin 11
int CWLED = 7;             // CW LED Indicator
int CCWLED = 6;            // CCW LED Indicator
int WAITLED = 5;           // WAIT LED Indicator
#define CYCLE_TIMES 3000L

void setup()               // run once, when the sketch starts
{
  // sets the digital pins as output
  pinMode(CCW, OUTPUT);    //close front
  pinMode(CW, OUTPUT);     //close rear
  pinMode(CWLED, OUTPUT);  //yellow
  pinMode(CCWLED, OUTPUT); //green
  pinMode(WAITLED, OUTPUT);  //red
  
}


void loop()                // run over and over again
{
  for (long i= 0; i < CYCLE_TIMES; ++i) {  
      digitalWrite(CCW, LOW);           // sets the CCW pin LOW to tell the board to run for ontime
      digitalWrite(WAITLED, LOW);
      digitalWrite(CCWLED, HIGH);
      delay(5500);                   // wait seconds = OnTimeCCW, 5500 minimum
      digitalWrite(CCW, HIGH);          // sets the CCW pin HIGH to tell the board to stop running
      digitalWrite(CCWLED, LOW);
      digitalWrite(WAITLED, HIGH);
      delay(1000);                     // wait seconds = offtime
      digitalWrite(CW, LOW);            // sets the CW pin LOW to tell the board run for ontime
      digitalWrite(CCWLED, LOW);
      digitalWrite(WAITLED, LOW);
      digitalWrite(CWLED, HIGH);
      delay(5500);                     // wait seconds = OnTimeCW, 5500 minimum
      digitalWrite(CW, HIGH);           // sets the CW pin HIGH to tell the board to stop running
      digitalWrite(CWLED, LOW);
      digitalWrite(WAITLED, HIGH);
      delay(2000);                     // wait seconds = offtime
  }
 
  for (;;) {;}
}

My fault in the final “for” loop. - Mis-typed {;;} instead of (;:wink:

Beautiful. You now are also credited in the code. Thank you!