Variable value not being recognised

My code was working well until I added a test during setup to choose the value of the variable called 'interval'. Previously, with that value set to say 10000 ms, the serial monitor was correctly displaying data at approx 10s intervals. But now, after the test, the value appears to be zero, instead of either 10s or 160s, and the monitor is printing lines about every 400 ms.

I've spent hours so far today tryng in vain to identify my error. At one stage I noticed that 'interval' is coloured red and thought that might be an obscure factor. But changing to 'gap' made no difference to the frequency. (Just the colour! Is there something special about the string 'interval'?).

As you'll notice, the setup switch (controlled by I/O pin 4) was originally used to choose another variable, called videoLength, so I've used the same approach as I did then. Including declaring it in two places, as advised months ago when discussing the earlier stages of this project.

/*
  Use radical new method
  Power up omly in setup, then take photo at intervals to keep power up.
    Pins used: 4 (video duration setting), 6 (trigger servo sequence),
    8 (video LED) and 9 (Servo).
*/
// This uses a keep-alive signal to maintain power; it takes an (unwanted) photo
// on each occasion

// Recent change: Expressed times in minutes to 2dp
// Recent change: Restarts interval counter at end of a video
// (as the video itself was a keep-alive event)

// #include <Servo.h> // Uses code from the Arduino library
#include <VarSpeedServo.h> // Uses the VarSpeedServo library

//  Servo myservo;  // "Create servo object to control a servo"
VarSpeedServo myservo;

const byte outPos = 17;
const byte inPos = 5; // So rotation is 12 degs
const byte triggerPin = 6; // Triggers start of video
const byte delayPeriod = 250; // Delay between successive press/releases
const byte waitBeforeRelease = 200; // Was 200
const byte redledPin = 8; // (Blue LED on bb)
const byte switchPin = 4;
int videoLength; // Needs declaring here as well as in setup
unsigned long previousMillis = 0; // Stores last time LED was updated
unsigned long interval; // 'Keep-alive' interval, at which to take photo

int countPhotos; // Counts number of photos
int countVideos; // Counts number of videos
int Mins;

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

void setup()
{

  Serial.begin(115200);
  Serial.println("PhotosPlusVideos-4");

  unsigned long interval;
  myservo.attach(9);
  pinMode(switchPin, INPUT_PULLUP);
  pinMode(triggerPin, INPUT_PULLUP);
  pinMode(redledPin, OUTPUT);
  myservo.write(outPos); // Rotates to the 'Out' position
  delay(1000);
  // Power up CUBE
  myservo.write(inPos);
  delay(3200); // Press for > 3s to power up; Was 3200/3100/3500
  myservo.write(outPos);
  delay(2000); // Delay before starting video.
  // That delay was originally 200! Now need full 2 s. Even 1500 ms failed.


  // Test D4 to choose value of videolength and interval
  if (digitalRead(switchPin) == HIGH)
  {
    videoLength = 30000;
    unsigned long interval = 160000; // 'Keep-alive' interval nearly 3 mins
  }
  else
  {
    videoLength = 5000; // 5 s for testing
    unsigned long interval = 10000; // 10 s for testing
  }

  countPhotos = 0; // Set to zero after power-up or reset
  countVideos = 0; // Set to zero after power-up or reset
  Serial.print("interval = ");
  Serial.println(interval); // THIS REPORTS ZERO! WHY??
}

void loop()
{
  unsigned long currentMillis = millis();
  // If time for a keep-alive photo has been reached
  if (currentMillis - previousMillis >= interval)
  {
    // Take a photo, i.e press and release camera button once
    myservo.write(inPos);
    delay(waitBeforeRelease);
    myservo.write(outPos);
    delay(200);
    previousMillis = currentMillis; // Save the last time a photo was taken
    countPhotos++; // Increment the photo count
    Serial.print("'Keep alive' photo number ");
    Serial.print(countPhotos);
    Serial.print(" was taken ");
    Serial.print(ms2Mins(millis()));
    Serial.println(" mins since program started");

  }

  // The following 'video loop' will be run only when a LOW on D6 is detected

  if (digitalRead(triggerPin) == LOW)
  {

    // Two button presses to start video
    myservo.write(inPos); // 1st of 2 presses
    delay(waitBeforeRelease);
    myservo.write(outPos);
    delay(200); // Was 200

    myservo.write(inPos); // 2nd of 2 presses
    delay(waitBeforeRelease);
    myservo.write(outPos);
    // Video is now running. Stop it after videoLength.
    digitalWrite(redledPin , HIGH) ;
    delay(videoLength);
    // Single press/release to stop video
    myservo.write(inPos);
    delay(waitBeforeRelease);
    myservo.write(outPos);
    digitalWrite(redledPin , LOW) ;
    // 'Restart' the interval monitoring
    previousMillis = millis();

    countVideos++;
    Serial.print("Video number ");
    Serial.print(countVideos);
    Serial.print(" finished recording roughly ");
    Serial.print(ms2Mins(millis()));
    Serial.println(" mins since program started");
    Serial.println(); // Blank line

  }

}

// Function 'ms2Mins to convert ms to minutes
float ms2Mins(unsigned long ms)
{
  float Mins = (ms / 60000.0);
  return Mins;
}

FWIW here also is some output from the serial monitor:

By declaring Inerval within the block of code following the if statement you have a local variable that is only applicable to that block of code and as soon as you leave that block of code the variable is gone. Any reference to Interval outside that block of code uses the global version.

if (digitalRead(switchPin) == HIGH)
  {
    videoLength = 30000;
    unsigned long interval = 160000; // 'Keep-alive' interval nearly 3 mins
  }
  else
  {
    videoLength = 5000; // 5 s for testing
    unsigned long interval = 10000; // 10 s for testing
  }

I believe you just need to remove the unsigned long declaration within those if blocks to get what you want.

You have more than one variable named interval, each with its own scope

This:

    unsigned long interval = 160000; // 'Keep-alive' interval nearly 3 mins

Declares and initializes a new variable which immediately goes out of scope. The global interval variable is never touched.

Drop the words unsigned long from this and the other similar occurrences.

What a relief! Thanks all, that was it, redundant declaration(s).