
\ A small example how to use the LEDs and buttons on the breakaway section


\ Bits on Port 3:

\ 0   1  Led West
\ 1   2  Led East
\ 2   4  Led South
\ 3   8    Button 2
\ 4  16  Led Middle
\ 5  32  Led North
\ 6  64    Button 1
\ 7 128    Button 3

: inout ( -- )

  %00110111 $400 io! \ Set LEDs as outputs, buttons as inputs

  begin
    $100 io@ \ Read buttons
    64 8 128 or or and \ Mask the button bits

    case
      64 of  1 2 or $200 io! endof \ West and East
       8 of 32 4 or $200 io! endof \ North and South
     128 of 32 4 1 2 or or or $200 io! endof \ All four directions
    
      16 $200 io!  \ Default: Red LED in the middle
    endcase

  key? until

  0 $400 io! \ All pins as inputs
;


: blinky ( -- )

  %00110111 $400 io! \ Set LEDs as outputs, buttons as inputs

  begin
    1 $200 io! 200 ms
   32 $200 io! 200 ms
    2 $200 io! 200 ms
    4 $200 io! 200 ms
  key? until

  0 $400 io! \ All pins as inputs
;
