\ FLASH AN LED by Professor Braino - updated from PropForth 2.5 by BrianBR
\ using PROPFORTH 3.2 (a new version of salsanci spinforth 1.1)
\ (This is NOT propellerforth from Cliffe Biffle)
\ load PropForth.spin into eeprom and use a terminal program too 'send textile' at 1 ms per char / 1ms per line 
\   PC/Win "teraterm"   Mac OSX "ZTerm" set to 57600 8n1  baud worked best for me
\ 
\ will run on an unmodified 'Demo' board
\ each unit of functionality is implemented as a single word
\ when each word is functioning correctly, string them together

variable w-delay \ ( uses w@ w! time delay in milliseconds )
: !DELAY w-delay W! ; \ ( ms - ) ( store the milliseconds to wait )
: .DELAY w-delay W@ delms ; \ ( - ) ( wait for milliseconds in delay )

: pin16-output 10000 dira COG! ; \ ( - ) ( make pin16 output )
: pin16-hi 10000 outa COG! ; \ ( - ) ( make pin16 high LED ON )
: pin16-lo 0 outa COG! ; \ ( - ) ( make pin16 low LED OFF )

\ ... string them together...

: flash16 pin16-hi .DELAY pin16-lo .DELAY ; \ ( - ) ( flash LED using DELAY )

\ ... and put it in a loop

: FLASHES pin16-output 0 do flash16 loop ; \ ( number of flashes desired - )

\ After one has determined what code is needed, it is possible to
\ cram everything into a single word
\ doing everything all in one word is sometimes referred to as
\ write only code (write once - edit never again )
\ this takes slightly less space but can be confusing on larger applications
\ after the code has been left alone for a few days

: ALL-ONE-WORD \ ( flashes - )
10000 dira COG! \ ( make pin16 output )
0 do \ flashes to 0 DO ...
10000 outa COG! \ ( make pin16 high LED ON )
100 delms \ ( delay for 100 ms)
0 outa COG! \ ( make pin16 low LED OFF )
100 delms
loop ;

\ 10 ALL-ONE-WORD
\ next use the other method

\ 50 !DELAY
\ 20 FLASHES
