module Module {
  var mG: boolean;
  var mR: boolean;
  var mY: boolean;
  var sG: boolean;
  var sR: boolean;
  var sY: boolean;
  var vehicle_detected: boolean;
  var timer: integer;
  var main_light: integer;
  var secondary_light: integer;

  input vehicle_sensor: boolean;

  next {
    if (vehicle_sensor) {
      vehicle_detected' = true;
    } else {
      vehicle_detected' = false;
    }
    if (vehicle_detected) {
      main_light' = 1;
      secondary_light' = 0;
    } else {
      if (timer < 240) {
        if (timer >= 180) {
          main_light' = 2;
          secondary_light' = 1;
        } else {
          if (timer >= 175) {
            main_light' = 2;
            secondary_light' = 1;
          } else {
            main_light' = 1;
            secondary_light' = 0;
          }
        }
      } else {
        timer' = 0;
      }
    }
    timer' = (timer + 1);
    mG' = (main_light == 0);
    mY' = (main_light == 2);
    mR' = (main_light == 1);
    sG' = (secondary_light == 0);
    sY' = (secondary_light == 2);
    sR' = (secondary_light == 1);

  }
}
