( LED Panel on Arduino Uno ) ( Chen-Hanson Ting, 5/15/2011 ) ( Sink: PC: 5, 4, 3, 2, 1, 0 ) ( PB: 3, 2 ) ( Drive: PB: 1, 0 ) ( PD: 7, 6, 5, 4, 3, 2 ) ( load LEDpanel_1, LEDpanel_2, ASCII, and STRING files ) DECIMAL VARIABLE RND ( seed ) : (RANDOM) ( -- n, a random number within 0 to 65536 ) RND @ 31421 * ( RND*31421 ) 6927 + ( RND*31421+6926, mod 65536) DUP RND ! ( refresh he seed ) ; : RANDOM ( n1 -- n2, a random number within 0 to n1 ) (RANDOM) UM* ( n1*random to a double product) SWAP DROP ( discard lower part ) ; ( in fact divide by 65536 ) hex variable ticks variable scans : init-ports f 24 c! 3f 27 c! fc 2a c! \ output ports ; : ms ( n -- ) for aft 100 for next then next ; : delay ticks @ ms ?key abort" done" ; : lshift ( n n -- ) for aft 2* then next ; : rshift ( n n -- ) for aft 2/ then next ; : drive ( n -- ) 0 25 c! 0 28 c! 0 2b c! ff00 xor dup 2* 2* 2b c! \ PD outputs 6 rshift dup f and 25 c! \ PB outputs 4 rshift 3f and 28 c! \ PC outputs delay ; : sequence1 1 7 for 100 7 for 2dup + drive 2* next drop 2* next drop ; : sequence2 100 7 for 1 7 for 2dup + drive 2* next drop 2* next drop ; : demo1 ( ticks -- ) ticks ! init-ports begin sequence1 again ; : demo2 ( ticks -- ) ticks ! init-ports begin sequence2 again ; cp @ 122 , 240 , 48c , 811 , 1022 , 2040 , 4088 , 8011 , constant red cp @ 140 , 29c , 411 , 822 , 1040 , 208c , 4011 , 8022 , constant yellow cp @ 18c , 201 , 422 , 840 , 108c , 2011 , 4022 , 8040 , constant green cp @ 111 , 222 , 440 , 88c , 1011 , 2022 , 4040 , 808c , constant blue cp @ 101 , 201 , 401 , 801 , 1001 , 2001 , 4001 , 8001 , 102 , 202 , 402 , 802 , 1002 , 2002 , 4002 , 8002 , 104 , 204 , 404 , 804 , 1004 , 2004 , 4004 , 8004 , 108 , 208 , 408 , 808 , 1008 , 2008 , 4008 , 8008 , 110 , 210 , 410 , 810 , 1010 , 2010 , 4010 , 8010 , 120 , 220 , 420 , 820 , 1020 , 2020 , 4020 , 8020 , 140 , 240 , 440 , 840 , 1040 , 2040 , 4040 , 8040 , 180 , 280 , 480 , 880 , 1080 , 2080 , 4080 , 8080 , constant 1lines cp @ 111 , 211 , 411 , 811 , 1011 , 2011 , 4011 , 8011 , 122 , 222 , 422 , 822 , 1022 , 2022 , 4022 , 8022 , 144 , 244 , 444 , 844 , 1044 , 2044 , 4044 , 8044 , 188 , 288 , 488 , 888 , 1088 , 2088 , 4088 , 8088 , constant 2lines : scan ( a -- ) scans @ for dup 7 for dup I@ drive 2+ next 2- 2- 5 for dup I@ drive 2- next drop next drop ; : colors 3 for red scan yellow scan green scan blue scan next ; : progressive ( a -- ) 3 scans ! 40 ticks ! dup scan 7 scans ! 1 ticks ! dup scan ; : next-line ( n -- n' ) for 10 + dup progressive next ; : demo3 1lines dup progressive 6 next-line drop 2lines dup progressive 2 next-line drop 2lines dup progressive 2 next-line drop ; : lines ( a n -- ) 40 scans ! 1 ticks ! for dup scan 10 + next drop ; : demo4 begin 1lines 7 lines 2lines 3 lines again ; : demo5 init-ports 3 scans ! 20 ticks ! begin (random) drive again ; : select ( -- n ) 8 random 1 swap for aft 2* then next 8 random 100 swap for aft 2* then next or ; : s. select . ; : r. (random) . ; : demo6 init-ports 3 scans ! 20 ticks ! begin select drive again ; : demo init-ports cp @ RND ! begin 10 ticks ! 7 scans ! 7 for sequence1 next 200 ticks ! 7 for ffff drive 0 drive next 3 scans ! 20 ticks ! colors 20 ticks ! 200 for (random) drive next 10 ticks ! 7 scans ! 7 for sequence2 next 20 ticks ! 200 for select drive next again ; flush init-ports cp @ RND !