Im trying to simulate traffic light system.
so the variables would be test1 = traffic light A is green
test2 = traffic light B is green ( omit orange lights)
so say for 100 seconds
|
if ( i == 0){ test1 = true; } // start by setting trafic light A to green
| |
1 2 3 4 5 6 7
|
if ( test1 == true){ // if trafic light A is green
if(a<=10){ a++; } // if we did not reach 10 sec a++
if(a > 10) { //if we dd reach 10 sec
b = 0; // set counter for trafic light B to 0;
test2 = true; // turn on light B
test1 = false; // turn off light A
}
| |
this code means if the traffic light A is green then let the light run for 10 seconds
and once it reaches 10 seconds turn traffic light A off and turn on traffic light B.
and same for traffic light B. if its on let it run for 10 seconds and after 10 seconds turn
off light B and turn on light A.
what i expact the is traffic light to be turned on
0 sec - A turn on
10 sec - B turn on
20 sec - A trn on
and so on 30 40 50 60 70 80 90 100.
what im getting is
0 sec - A turn on
10 sec - B turn on
20 sec - A turn on
31sec - B turn on
41 sec - A turn on
52 sec - A turn on
62 sec - B turn on
So i need help with when reaching /////HERE/// line what ever variable changed above to
effect below inside loop.(I know it will change once out of loop and re-entering loop )
Hope I explained it well. please let me know if i need to explain more :)
thank you for helping me out.!! ^^
PS: 10 sec is just sample i will later try to figure out minimum times for both queue