( Traffic Controller on Arduino Uno ) ( Chen-Hanson Ting, 5/10/2011 ) ( Switches: PC: 0, N; 1, NL; 2, S; 3, SL; 4, W; 5, WL ) ( PB: 2: E; 3, EL ) ( LEDs: PD: 2, nsG; 3, nsY; 4, nsR, 5, nsL; 6, ewG; 7,ewY ) ( PB: 0, ewR; 1,ewL ) hex : init-ports fc 2a c! 3 24 c! \ output ports 3f 28 c! c 25 c! ; \ input ports, pullup resistors : seconds for aft 100 for 400 for next next then next ; : lights ( n -- ) dup 2b c! \ PD outputs 100 / C or 25 c! ; \ PB outputs, maintain pullups : switches ( -- n ) 23 c@ 100 * \ PB inputs 26 c@ or \ PC inputs dup cr . ; : N-S begin 104 lights 5 seconds switches c3a and if 108 lights 2 seconds then switches a and if 130 lights 3 seconds then switches c30 and until ; : E-W begin 50 lights 5 seconds switches 82f and if 90 lights 2 seconds then switches 820 and if 310 lights 3 seconds then switches f and until ; : go init-ports begin N-S E-W ?key until drop ; flush \ ************************************************************* \ Above program was written using 328eForth for Arduino Uno Board. \ 328eForth is available from www.offete.com for $25. \ You can have a free copy if you send an email to \ ting@offete.com \ For information and public domain Forth compilers, visit \ www.forth.org \ To learn Forth programming language and operating systems, \ join Silicon Valley Forth Interest Group (SVFIG). \ Check meeting place and announcement at \ www.forth.org/svfig/next.html \ www.meetup.com/SV-FIG/ \ *************************************************************