 
 void loop() {
   // put your main code here, to run repeatedly:
+  timeSinceStart = millis();
+
+  switch (traffic) {
+    case NS_GREEN:
+      if (vehicleEWCounter > 0) {
+        changeEWGreenToAmber();
+      }
+      break;
+    case EW_GREEN:
+      if (vehicleNSCounter > 0) {
+        changeNSGreenToAmber();
+      }
+      break;
+    case NS_AMBER:
+      changeNSAmberToRed();
+      break;
+    case NS_RED:
+      changeNSRedToEWGreen();
+      break;
+    case EW_AMBER:
+      changeEWAmberToRed();
+      break;
+    case EW_RED:
+      changeEWRedToNSGreen();
+      break;
+    default:
+      break;
+  }
 
   //check on our threads. based on how long the system has been
   //running, do they need to fire and do work? if so, do it!
   vehiclesNSThread.check();
   vehiclesEWThread.check();
-  signalThread.check();
   vehicleRemovalThread.check();
 
   vehicleEWState = digitalRead(vehicleEW);

const int vehicleNS = 13;

// Light delay
int delayTime = 1000; //1sec

// Light delays
int amberLightDelay = 2000; //2sec
int greenLightDelay = 5000; //20sec for now 5 sec
int redLightDelay = 3000; //3 sec

//boolean to control state
boolean isNSTrafficGreen = false;

int vehicleNSCounter = 0;   // counter for the number of button presses
int vehicleNSState = 0;        // current state of the button
int lastVehicleNSState = 0;    // previous state of the button

int vehicleEWCounter = 0;   // counter for the number of button presses
int vehicleEWState = 0;        // current state of the button
int lastVehicleEWState = 0;    // previous state of the button

//FUNCTIONS


  lastVehicleEWState = vehicleEWState;
}

/**
   Passes vehicles
*/
void passVehicles() {
  //pass vehicles only after minimum vehicle time
  if (timeSinceStart - previousVehicleTime > vehicleTime) {
    //Pass any blocked vehicles in NS traffic
    if (traffic == NS_GREEN) {
      //when NS traffic cycle change traffic to north south
      if (vehicleNSCounter > 0 && (timeSinceStart - timeWhenGreenSignal > vehicleTime)) {
        vehicleNSCounter = vehicleNSCounter - 1;
        Serial.print("Vehicle NORTH-SOUTH passing. Total vehicles remainning: ");
        Serial.println(vehicleNSCounter);
        previousVehicleTime = timeSinceStart;
      }
    }

    if (traffic == EW_GREEN) {
      //when NS traffic cycle change traffic to north south
      if (vehicleEWCounter > 0 && (timeSinceStart - timeWhenGreenSignal > vehicleTime)) {
        vehicleEWCounter = vehicleEWCounter - 1;
        Serial.print("Vehicle EAST-WEST passing. Total vehicles remainning: ");
        Serial.println(vehicleEWCounter);
        previousVehicleTime = timeSinceStart;
      }
    }
  }
}

//creates a couple timers that will fire repeatedly every x ms
TimedAction vehiclesNSThread = TimedAction(50, countNSVehicles); // checks for NS vehicle every 50 sec and count the total vehicle
TimedAction vehiclesEWThread = TimedAction(50, countEWVehicles); // checks for ES vehicle every 50 sec and count the total vehicle
TimedAction vehicleRemovalThread = TimedAction(1000, passVehicles); //a vehicle take minimum 5 to pass


// where's our third task? well, it's the loop itself :) the task
