[SOLVED] - Time in variable is wrong. ??

Hey guys.

I have a homework assignment where i need to make a
stoplight function that has 2 different stages, depending on day or night.

I have set a couple of variables with time in milliseconds.
The strange thing i am running into is that all time variables work correctly accept 1.

I have the timer set to 90000 milliseconds and the monitor returns 24464.
If i change the time to something lower then 31000, i get the correct results in the monitor.

If i take out the variable and simply place the time (90k) into the delay directly, it seems to work.

Right now i have no clue to what causes this issue to arise.

Could anyone explain to me why i am unable to declare a time above 31k into a variable ?

Many thanks.

PS. this is the code i have so far.
It is not finished nor cleaned up.

// Stoplight assignment
// Educational lesson 7

const int car[] = {2,3,4};
const int bike[] = {8,9,10};
const int sensor = A5;
int sensorstate = 0;

const int greenLightTimerBikes = 20000;
const int greenLightTimerCars = 90000;
const int redLightTimerCars = 20000;
const int orangeLightBlinker = 350;
const int switchDelay = 3000;

int active = 0;

void setup() {
  Serial.begin(9600);
  // Initialize pins for the car lane
  for (int i = 2; i < 5; i++) {
    pinMode(i, OUTPUT);
  };

  // Initialize pins for the bike lane
  for (int i = 8; i < 11; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  sensorstate = analogRead(sensor);
  //  Serial.println(sensorstate);

  if (active == 1) return;

  if (sensorstate > 800) return daylightRoutine();
  if (sensorstate < 500) return nightlightRoutine();
}

void daylightRoutine() {
  active = 1;

  // Turn red light cars offline if they are live.
  digitalWrite(car[0], LOW);

  // Set green light for cars active.
  digitalWrite(car[2], HIGH);
  // Set red light for bikers.
  digitalWrite(bike[0], HIGH);
  Serial.println(test);
  delay(test);

  // Deactivate green light for cars.
  digitalWrite(car[2], LOW);

  // Start red light warning for the cars.
  for (int i = 0; i < 5; i++) {
    digitalWrite(car[1], HIGH);
    delay(orangeLightBlinker);
    digitalWrite(car[1], LOW);
    delay(orangeLightBlinker);
  }

  // Set cars to have a red light.
  digitalWrite(car[0], HIGH);
  delay(switchDelay);

  // Set green light for bikers.
  digitalWrite(bike[0], LOW);
  digitalWrite(bike[2], HIGH);
  delay(greenLightTimerBikes);
  digitalWrite(bike[2], LOW);

  // Start red light warning for the bikers.
  for (int i = 0; i < 5; i++) {
    digitalWrite(bike[1], HIGH);
    delay(orangeLightBlinker);
    digitalWrite(bike[1], LOW);
    delay(orangeLightBlinker);
  }

  // Set red light for bikers.
  digitalWrite(bike[0], HIGH);
  delay(switchDelay);

  // deactivate the system
  active = 0;
  return loop();
}

void nightlightRoutine() {}

An int variable, of 16 bit, can only hold values up to 32k, unsigned int up to 64k, and time usually is kept in unsigned long variables.

Yes awesome !!
Many thanks DrDiettrich.
That was indeed my issue :smiley: