top of page

Traffic Light

Pressing a button on pin C1 cycles the USER LED traffic light through green, orange and red.

Program


---

Traffic Light Program

Pressing a button on pin C1 cycles the

USER LED traffic light through green, orange and red.

---


prog_vars =

-- Traffic Light State

-- 1 = green 2 = orange 3 = red

d/tl_state 1

prog_vars.


prog_start =

pclear

print "Traffic Program Start"

-- Setup the button

btp c1 change_light

-- Set the light to red by default

l1 3

prog_start.


prog_loop =

-- main program loop

patdog



prog_loop.


change_light =

-- Button pressed


-- Move to next state

any /tl_state <= 3 ->

inc /tl_state

enda.

-- Reset back to green

any /tl_state >= 4 ->

/tl_state 1

enda.

-- Update the color

ant /tl_state ->

= 1 -> l1 8

= 2 -> l1 5

= 3 -> l1 3

-> l1 3

ant.


print "New State /tl_state"


change_light.

prog_stop =

print "Bye"

prog_stop.



bottom of page