Long Duration Timming

I am wanting to cycle two pins that will control solid state relays. I would like to have a push button start the loop and the loop continue to run until I reach a specific number of loop cycles.After that condition has been met the loop stops and does not run until I reset the controller.

I am using a Uno and have hacked out some basic code that has the sequence of the pins correct but I am using delays as my programming skills are still at the NOOB stage, can't quite seem to wrap my head around this.

I have a LCD display that is displaying the # of cycles but the display does not update naturally until I get through all of the delays. Now saying that I do not need anything to run at the same time just would like to update the display quicker. I know that the delay command is not what I want but don't understand how to implement the blink without delay example.

Sequence of events that I want to happen.

1 Push button to start loop
2 pin 7 goes high to start stirring motor
3 pin 7 stays high for 1hr & 5 min. // How do I do this long duration cleanly???
4 pin 7 goes low (motor off)
5 delay 3 sec
6 Pin 6 goes high 6.5 sec.
7 pin 6 goes low
8 delay 3 sec
9 count pin 6 cycle
10 display on LCD
11 loop back to step 2
12 cycle until given # of cycles have been reached then stop

Please be patient with me as I am trying to learn.

My Code attempt:

Please note that the times do not match the above sequence as these times are for testing the code quickly.

/*
  Feeding System Delivery code based on time
  Pin 5 connected to pinch valve solid state relay
  Pin 7 connected to stirring motor solid state relay
  Pin 6 start button

 

 

  16 Nov. 2014
 
 */
 #include <LiquidCrystal.h>
// Define LCD pins
LiquidCrystal lcd (12, 11, 3, 2, 1, 0);
const int pinchPin=5;
const int startPin=6;
const int motorPin=7;
int maxnum =22;
int count =0;

//int buttonState = 0;    // variable for reading the pushbutton status

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pins 5,7 as an output.
  // initialize digital pin 6 as an input.
  pinMode(pinchPin,OUTPUT);
  pinMode(startPin,INPUT);
  pinMode(motorPin, OUTPUT);
 
  lcd.begin(16,2);
  
}


void loop() {
 //buttonState = digitalRead(startPin);
  lcd.setCursor(2,0);
  lcd.print("# OF FEEDINGS");
  lcd.setCursor(7,1);

  //if ((buttonState == HIGH)&&(count < maxnum)){
    
  digitalWrite(pinchPin,LOW);     // pinch valve off for startup
  digitalWrite(motorPin, LOW);   // turn off stirring motor
  delay(5000);              // off time of pin 7 delay for stirring system
  digitalWrite(pinchPin,HIGH);     // pinch valve on
  delay (635);             // Feeding amount time
  digitalWrite(pinchPin,LOW);    //pinch valve off
  delay (1500);
  digitalWrite(motorPin,HIGH);     // Stirring Motor ON
  delay (15000);             //stirring motor run time set to 1hr5min
  
  count++;                   //count the number of feedings
  lcd.print(count);
  //while (buttonState == LOW);
  
}

_24hr_feeding.ino (1.51 KB)

After that condition has been met the loop stops

No it doesn't. It continues to loop while it's checking the state of the buttons. The user may decide to turn it on again!

Checking the time is part of the continuous loop.
Checking for user input is part of the continuous loop.

Based on what it finds in the user input or time check
it may Turn ON the relay, (it only needs to do this once)
It may turn OFF the relay (it only needs to do this once)

But the loop checking user input and the time continue.

void loop() {
    // 1 Push button to start loop
    if (digitalRead(ButtonPin)) {
        // 12 cycle until given # of cycles have been reached then stop
        for (int i = 0; i < NumberOfCycles; i++) {
            // 2 pin 7 goes high to start stirring motor
            digitalWrite(StirMotorPin, HIGH);
            // 3 pin 7 stays high for 1hr & 5 min.             // How do I do this long duration cleanly???
           delay(65 * 60000UL);  // 65 minutes
            //4 pin 7 goes low (motor off)
            digitalWrite(StirMotorPin, LOW);
            // 5 delay 3 sec 
            delay(3000);
            // 6 Pin 6 goes high  6.5 sec.
            digitalWrite(6, HIGH);
            delay(6500); 
            // 7 pin 6 goes low
            digitalWrite(6, LOW);
            // 8 delay 3 sec
            delay(3000);
            // 9 count pin 6 cycle
            // 10 display on LCD
            LCD.print(i+1);
            // 11 loop back to step 2
        } // End of NumberOfCycles loop
    while (1);  // Stop the program from doing anything else
    } // End of if (digitalRead(ButtonPin))
} // End of loop()

Thanks Johnwasser for the code. I could not get the code to run as the uno was not seeing the button to start the loop. I am just not understanding the i function. As I am writing this response should I have declared numberofcycles with a value in setup?

Thanks again !

I did the best I could with the information provided. You said to repeat for the maximum number of cycles but you gave no value for that so I used a named variable you could define and set as you saw fit.

In your sketch you use Pin 6 for the button but in your list of operations you are using Pin 6 as an output. Perhaps you meant to specify the pin connected to the pinch valve.

Best to define your pins by name at the top of the program and use the names. In setup() you would set pinMode() and whatever initialization your LCD needs.