How to use timer in traffic light that use sensors?
<p>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 ..</p>

<pre><code>while((n1&gt;OSi) &amp;&amp; (t!=max)) { //n1,n2 are number of cars that counted by IS"In sensor". OS "outer sensor.
    if (button4-&gt;BackColor == System::Drawing::Color::Green) {
        button4-&gt;BackColor==System::Drawing::Color::Gray;
        button5-&gt;BackColor==System::Drawing::Color::Yellow;
    }

    button6-&gt;BackColor = System::Drawing::Color::Red;
    button1-&gt;BackColor = System::Drawing::Color::Green;
    t++;
}

if ((n1&gt;0) &amp;&amp; (n2!=0)) {
    button1-&gt;BackColor = System::Drawing::Color::Gray;
    button2-&gt;BackColor=System::Drawing::Color::Yellow;
    button2-&gt;BackColor=System::Drawing::Color::Gray;
    button3-&gt;BackColor=System::Drawing::Color::Red;
}

t=1;

if (n2 != 0)
while((n2&gt;osj) &amp;&amp;( t!=max)) {
    button3-&gt;BackColor=System::Drawing::Color::Red;
    button4-&gt;BackColor=System::Drawing::Color::Green;
    t++;
}

n1=rand(); //rand()%number .. this to get random number of the cars.

if (n1&gt;0)
if (button4-&gt;BackColor==System::Drawing::Color::Green)
{
    button4-&gt;BackColor=System::Drawing::Color::Gray;
    button5-&gt;BackColor=System::Drawing::Color::Yellow;
    button5-&gt;BackColor=System::Drawing::Color::Gray;
    button6-&gt;BackColor=System::Drawing::Color::Red;
}

n2=rand();
</code></pre>

<p>thank you everyone ..</p>
