Skip to first unread message

nitu gupta

unread,
Dec 27, 2015, 11:01:28 AM12/27/15
to MIT App Inventor Forum
i am trying to simulate a traffic light and glow green, yellow, red lights in sequence for some duration.
If i run separate timers for each of them and make the timers 'always enabled' and 'always fire' then there seems to be some synchronization problem.

Can anybody provide more tips for simulating these ?

thanks in advance,
Nitu

Italo

unread,
Dec 27, 2015, 11:14:49 AM12/27/15
to MIT App Inventor Forum
Don't do 3 separate timers. Do only one and change the interval depending on the current color.

Taifun

unread,
Dec 27, 2015, 11:16:36 AM12/27/15
to MIT App Inventor Forum
what about using only one clock component together with a counter variable?

pseudo code for the clock.timer event
counter = counter + 1
if counter < 20
then display green light
else if counter < 25
then display yellow light
else display red light
if counter > 40 then counter = 0

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         










Tim Carter

unread,
Dec 28, 2015, 7:29:18 AM12/28/15
to MIT App Inventor Forum
For a true simulation won't you at least need two timers, because red and amber need to come on at the same time (or red on first then amber on, then both off and green on) ? I could be wrong...

Taifun

unread,
Dec 28, 2015, 4:11:39 PM12/28/15
to MIT App Inventor Forum
one timer is sufficient...
updated pseudo code for the clock.timer event, adjust it to your needs...
counter = counter + 1
if counter < 20
then display green light
else if counter < 25
then display yellow light and display red light
else display red light
if counter > 40 then counter = 0

Taifun

Tim Carter

unread,
Dec 29, 2015, 5:44:23 AM12/29/15
to MIT App Inventor Forum
Ah yes :)
Reply all
Reply to author
Forward
0 new messages