Changing delay in sketch

Hi everyone,

I am new to arduino, and I am having trouble understanding "blink without delay" example.

What I want to achieve is have 3 different relays triggered for various times. These times are not all the same, and are +-30 different times.

I've written the entire sketch using delay, but would like to change delay to something else, in order to bring in a timer displaying amount of time left before loop end. The times i've put in is only for testing. The actual intervals vary from 5secs to 8Hours.
See below: (Ignore the comments that do not make sense)- Please Help!

int right=8;//right relay//
int left=10;//left relay//
int down=13;//down relay//
int ButtonTwo=2;//trigger 2 day programme//
int ButtonFive=4;//trigger 5 day programme//
int ButtonSeven=7;//trigger 7 day programme//

void setup() { //Setup runs once//

pinMode(right, OUTPUT); //Set right as an output//
pinMode(left, OUTPUT); //Set left as an output//
pinMode(down, OUTPUT); //Set down as an output//
pinMode(ButtonTwo, INPUT_PULLUP); //Set twoDay as an input//
pinMode(ButtonFive, INPUT_PULLUP); //Set fiveDay as an input//
pinMode(ButtonSeven, INPUT_PULLUP); //SetsevenDay as an input

}

void loop() { //Loop runs forever//
if(digitalRead(ButtonTwo)==LOW)
{
delay(10000); //for 3.5 seconds//
digitalWrite(right,HIGH); //Motor runs clockwise, Step 1//
delay(1000); //for 3.5 seconds//
digitalWrite(right, LOW); //Motor stops//
delay(1000); //Motor right wait for 2hours//
digitalWrite(left,HIGH); //Motor runs left//
delay(1000); //for 1 second//
digitalWrite(left,LOW); //Motor left Stops//
delay(1000); //Motor left stop for 1 second//
digitalWrite(left,HIGH); //Motor runs left//
delay(1000); //for 1 second//
digitalWrite(left,LOW); //Motor left Stops//
delay(1000); //Motor left stop for 1 Second//
digitalWrite(left,HIGH); //Motor runs left, Step 4//
delay(1000); //for 1 second//
digitalWrite(left,LOW); //Motor left Stops//
delay(1000);

and it go on like this endlessly.

This is one possible way to have no delays and produce similar sequences.

int right=8;//right relay//
int left=10;//left relay//
int down=13;//down relay//
int ButtonTwo=2;//trigger 2 day programme//
int ButtonFive=4;//trigger 5 day programme//
int ButtonSeven=7;//trigger 7 day programme//
void setup() {
  // put your setup code here, to run once:

  pinMode(right, OUTPUT); //Set right as an output//
  pinMode(left, OUTPUT); //Set left as an output//
  pinMode(down, OUTPUT); //Set down as an output//
  pinMode(ButtonTwo, INPUT_PULLUP); //Set twoDay as an input//
  pinMode(ButtonFive, INPUT_PULLUP); //Set fiveDay as an input//
  pinMode(ButtonSeven, INPUT_PULLUP); //SetsevenDay as an input
}

void loop() {
  // put your main code here, to run repeatedly:
  static unsigned long Counter;
  static unsigned long _Timer;
  if ( millis() - _Timer >= (100)) {  // Shortest Loop .1 seconds 10 times a second
    _Timer += (Seconds);
    Counter++; // counts 10 times a second
    switch (Counter) {
      case 1:
        StopAll();
        Mode = 1;
        break;
      case 35: // 3.5 Seconds
        StopAll();
        Mode = 2;
        break;

      case 600: // 1 Minute
        StopAll();
        Mode = 3;
        break;

      case 1200: // 2 Minute
        StopAll();
        Mode = 3;
        break;

      case 36000: // 1 hour
        StopAll();
        Mode = 3;
        break;

      case 36600: // 1hour 1 Minute
        StopAll();
        Counter = 0;
        break;
    }
  }

  switch (Mode) {
    case 1:
     digitalWrite(right,HIGH);
      break;
    case 2:
      static unsigned long _Timer2;
      if ( millis() - _Timer2 >= (10000)) {  // Shortest Loop .1 seconds 10 times a second
        _Timer2 += (Seconds);
        digitalWrite(left,!digitalRead(left)); //Motor runs left then stops every 10 seconds until the 1 minute mark where it will switch to Mode 3// 
      }
      break;
    case 3:
      static unsigned long _Timer3;
      if ( millis() - _Timer3 >= (20000)) {  // Shortest Loop .1 seconds 20 times a second
        _Timer3 += (Seconds);
        digitalWrite(right,!digitalRead(right)); //Motor runs right then stops every 10 seconds until the 1 minute mark where it will switch to Mode 3// 
      }
      break;
  }

  // You can put other code here just avoid any long delay()'s to prevent missing any of the transitions on time
}

void StopAll(){
  digitalWrite(right, LOW); //Motor right stops//
  digitalWrite(left,LOW); //Motor left Stops//
}

Hi zhomeslice,

Thank you for the reply.

I am learning so strugling to understand still. Another thing, where would I declare "Seconds"? And would i put my button trigger in loop before the "if(milis()?

int ButtonTwo=2;//trigger 2 day programme//
int ButtonFive=4;//trigger 5 day programme//
int ButtonSeven=7;//trigger 7 day programme//

Please explain the names and values. Why is ButtonFive assigned a value of 4?

PaulS:

int ButtonTwo=2;//trigger 2 day programme//

int ButtonFive=4;//trigger 5 day programme//
int ButtonSeven=7;//trigger 7 day programme//



Please explain the names and values. Why is ButtonFive assigned a value of 4?

Sorry I initially assumed that nothing would be less than 1 full second but later I saw you had a change at 3.5 seconds

  static unsigned long _Timer;[color=#222222][/color]
  if ( millis() - _Timer >= (100)) {  // Shortest Loop .1 seconds 10 times a second[color=#222222][/color]
    _Timer += (Seconds);

change to 

  static unsigned long _Timer;[color=#222222][/color]
  if ( millis() - _Timer >= (100)) {  // Shortest Loop .1 seconds 10 times a second[color=#222222][/color]
    _Timer += (100);

The two 100 's should match to keep the timing correct
100 miliseconds

because the loop runs fast you could put it right after the
void loop(){
button trigger
... other code