if switch is low start over... if still high continue process

I have a project that I am working on that is almost there! It does as I want except that I want the entire process to start over if the switch goes high and then back to low before a set amount of time. Basically I want the beam to be broken for say 4 seconds (time set by dip switch) and then execute. If switch does not stay high for x time and goes low then start the process over. Here is what I have thus far.

// Version X.13

// (c) Sunway Energy Solutions 2014

const int SWTCH1 = 2;					// Input pin for 1 second Timer Switch
const int SWTCH2 = 3;					// Input pin for 2 second Timer Switch
const int SWTCH4 = 4;					// Input pin for 4 second Timer Switch
const int SWTCH8 = 5;					// Input pin for 8 second Timer Switch
const int SENSOR = 7;					// Input pin for PIR Sensor
const int XMITTR = 10;					// Output pin for Transmitter
const int STROBE = 13;					// Output pin for strobe

int SENVAL = LOW;					// Set Sensor value
int SW1VAL = LOW;					// Set Switch 1 Value
int SW2VAL = LOW;					// Set Switch 2 Value
int SW4VAL = LOW;					// Set Switch 4 Value
int SW8VAL = LOW;					// Set Switch 8 Value
int DLYVAL = 0;						// Set initial Delay Value to 0

void setup()
{
  pinMode(SWTCH1, INPUT);				// Set SWTCH1 as input
  pinMode(SWTCH2, INPUT);				// Set SWTCH2 as input
  pinMode(SWTCH4, INPUT);				// Set SWTCH4 as input
  pinMode(SWTCH8, INPUT);				// Set SWTCH8 as input
  pinMode(SENSOR, INPUT);				// Set SENSOR as input
  pinMode(XMITTR, OUTPUT);				// Set XMITTR as output
  pinMode(STROBE, OUTPUT);				// Set STROBE as output

  SW1VAL = digitalRead(SWTCH1);				// Read Switch 1 value
  SW2VAL = digitalRead(SWTCH2);				// Read Switch 2 value
  SW4VAL = digitalRead(SWTCH4);				// Read Switch 4 value
  SW8VAL = digitalRead(SWTCH8);				// Read Switch 8 value

  if (SW1VAL == HIGH)					// Check Switch 1 Value
  {
    DLYVAL = DLYVAL + 1;				// Increment Delay Value by appropriate factor
  }

  if (SW2VAL == HIGH)					// Check Switch 2 Value
  {
    DLYVAL = DLYVAL + 2;				// Increment Delay Value by appropriate factor
  }

  if (SW4VAL == HIGH)					// Check Switch 4 Value
  {
    DLYVAL = DLYVAL + 4;				// Increment Delay Value by appropriate factor
  }

  if (SW8VAL == HIGH)					// Check Switch 8 Value
  {
    DLYVAL = DLYVAL + 8;				// Increment Delay Value by appropriate factor
  }
}

void loop()
{
  digitalWrite(STROBE, LOW);				// Turn off Strobe
  digitalWrite(XMITTR, LOW);				// Turn off Transmitter

  SENVAL = digitalRead(SENSOR);				// Read Sensor value
  if (SENVAL == HIGH)					// Check Sensor value
  {
    for (int DLYCNT = 0; DLYCNT <= DLYVAL; DLYCNT++)	// Run through loop for number of times per Delay Value
    {
       delay(1000);					// Delay for 1 second
    }

    SENVAL = LOW;					// Reset Sensor Value
    SENVAL = digitalRead(SENSOR);			// Read Sensor value again
    if (SENVAL == HIGH)					// Check Sensor value again
    { 
      digitalWrite(STROBE, HIGH);			// Turn on Strobe

      while (SENVAL == HIGH)				// Transmit until reset or power cycle
      {
        digitalWrite(XMITTR, HIGH);			// Turn on Transmitter
        delay(25000);					// Wait 25 seconds
        digitalWrite(XMITTR, LOW);			// Turn off Transmitter
        delay(5000);					// Wait 5 seconds
      }
    }
  }
}

You have a bug in your code here:

      while (SENVAL == HIGH)             // Transmit until reset or power cycle
      {
        digitalWrite(XMITTR, HIGH);         // Turn on Transmitter
        delay(25000);                   // Wait 25 seconds
        digitalWrite(XMITTR, LOW);          // Turn off Transmitter
        delay(5000);                    // Wait 5 seconds
      }

This will result in an infinite loop because the value of SENVAL will never change. You need to re-read the sensor and set the SENVAL variable inside of your while() loop. Like this:

      while (SENVAL == HIGH)             // Transmit until reset or power cycle
      {
        digitalWrite(XMITTR, HIGH);         // Turn on Transmitter
        delay(25000);                   // Wait 25 seconds
        digitalWrite(XMITTR, LOW);          // Turn off Transmitter
        delay(5000);                    // Wait 5 seconds
        SENVAL = digitalRead(SENSOR);           // Read Sensor value again
      }

I've added a digitalRead() for the sensor at the end of the loop. This loop will now continue indefinitely until SENVAL goes LOW. Hope this helps.

This helps some, however the point that I need it to restart if low is in this section:

SENVAL = digitalRead(SENSOR);				// Read Sensor value
  if (SENVAL == HIGH)					// Check Sensor value
  {
    for (int DLYCNT = 0; DLYCNT <= DLYVAL; DLYCNT++)	// Run through loop for number of times per Delay Value
    {
       delay(1000);					// Delay for 1 second
    }

    SENVAL = LOW;					// Reset Sensor Value
    SENVAL = digitalRead(SENSOR);			// Read Sensor value again

if it is still high through this entire process I want it to cycle until i physically push reset button. if it switches to low at all during this process I want it to start over. Basically lets say a deer walks through I don’t want it to sound. But if a car drives through I want it to finish and run the code. Maybe that clears is up a little.

I’m not really sure what you’re trying to do exactly… but the code at the top of your loop() function will execute again when the sensor goes back to HIGH. That is to say that when when your while() loop exits, the main loop will start again. If the SENVAL is LOW, nothing happens and the loop will just repeat without anything happening again until SENVAL goes HIGH again. Then your for loop is going to execute followed by your while loop. Provided, of course, that you added the missing line that I gave you.

I have an alarm that I want to go off along with lights until I physically turn them off once that sensor is broken. I want the sensor to be broken (high) for say 6 seconds (controlled by dip switch can be set 1-15 secs). if at any time during that 6 seconds the sensor beam is reconnected (goes low) i do not want anything to happen past that point. if it stays broken for 6 seconds then I want the alarm and lights to go off until i turn them off. i basically do not want false alarms caused by deer or people walking through, just large items such as cars and trucks.

Something like this pseudo code ?

void loop() {
   currMillis = millis();
   buttonState = readButton();
   if (currMillis - prevMillis > interval  && buttonState == HIGH) {
       soundAlarm();
   }
   if (buttonState == LOW)  {
      prevMillis = millis(); // reset the clock
   }
}

...R