How to use timer in traffic light that use sensors?

by using c++ windows form,how to use timer in traffic light that use sensors ,where in each cycle the time deffer between the traffic lights ..as you see here the output always is the last color the code didn't represent each color when its time come ..

I used values just to run the traffic light function because my program is not done yet and I want to check how the traffic light function works
but this is my code ..
I declared this in the public
int y,c;
double a,b;
int x1=0;
int x2=0;

this code below I put it in button1 ..
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//the program is about two traffic light on one way road,one in the sowth and other in west
//i start the program by assuming number of cars by using rand function
//i used three buttons on the both sides as traffic light just to change its color to represent red,yellow or green
y=Convert::ToInt16(textBox1->Text);
c=Convert::ToInt16(textBox2->Text);
a=Convert::ToDouble(rand() % y);//a is the number of cars for the west side,i used rand to get randome number
b=Convert::ToDouble(rand() % c);//b is the number of cars for the south side,i used rand to get randome number
textBox3->Text = Convert::ToString(a);
textBox4->Text = Convert::ToString(b);

int i=0;
if (a >= b)//here comparing a,b to see which traffic light would start
do
{
trafficlight(a,b,1,2);//calling function traffic light
i++;
}while (i<10);//here i assumed the program would run less than 10 times.
else
do
{
trafficlight(b,a,2,1);
i++;
}while (i<10);
}

void TrafficLight_1(int& n1, int& n2,int i,int j)
{
int max=60;
int t=1;
//os1,osj are output sensors that calculate the number of cars that pass when the traffic is green