fl fl { NeoPixelRing(WS2812:16pcs) PropForth 5.5 2014/03/29 22:29:02 Propeller NeoPixelRing P0 --- Data Input 5V ----------- 5V-PS GND --- GND ----------- GND } \ =========================================================================== \ Variables \ =========================================================================== \ LED-array for NeoPixelRing (64bytes:4bytes/1LED) variable NeoPixel d60 allot \ =========================================================================== \ Constants \ =========================================================================== 0 wconstant ser_out d16 wconstant LEDs variable Pixel -4 allot hFFFFFF l, h15ECED l, h50B3ED l, h8C78ED l, hBE45ED l, hF016ED l, hEF2F33 l, hEF5064 l, hEF87AA l, hEFADD5 l, hEFE1F2 l, hD5E1D6 l, hA6E1A4 l, h81E17E l, h57E14D l, h11E122 l, \ =========================================================================== \ Main \ =========================================================================== \ Send 16-data[GRB:24bits] to NeoPixelRing \ ( n1 n2 n3 -- ) n1:serial-out port n2:LED count n3:address for LED-array lockdict create _pixel_ring forthentry $C_a_lxasm w, h13E h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2Wi]BB l, z1SyLI[ l, z2Wi]JB l, z1SyLI[ l, z2Wy]O1 l, zfi]RB l, z1[ix[m l, z1bixnm l, z1SyLI[ l, z2Wi][w l, z20i]ak l, z3ry]W0 l, z2Wi]fk l, z2Wi]nl l, z8i]vo l, z20y]b4 l, zfy]r8 l, z2Wya0O l, zgy]r1 l, z2Wf][u l, z2WZ][s l, z1bix[m l, z20i]ak l, z3rf][v l, z3rZ][t l, z1[ix[m l, z3ry]W0 l, z3[ya4\ l, z3[y]nX l, z1SV04S l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, zS l, z10 l, zr l, zj l, zxW l, freedict \ Pack R-G-B byte to Long \ ( n1 n2 n3 -- n4 ) n1:R n2:G n3:B n4:G-R-B Long : color rot 8 lshift or swap d16 lshift or ; \ Pack R-G-B byte to Long and set each color to level \ ( n1 n2 n3 n4 -- n5 ) n1:R n2:G n3:B n4:level n5:G-R-B Long : colorx dup 0< if drop 3drop 0 \ If level<0 else dup d255 > if drop color \ If level>255 else dup \ ( n1 n2 n3 n4 n4 ) rot u* d255 u/ >r \ ( n1 n2 n4 ) dup \ ( n1 n2 n4 n4 ) rot u* d255 u/ >r \ ( n1 n4 ) u* d255 u/ r> r> \ ( n1' n2' n3' ) color \ ( n5 ) then then ; \ Set GRB value to position inside NeoPixel array \ GRB is packed Long in form G-R-B \ ( n1 n2 -- ) n1:G-R-B(Long) n2:position (0 to LEDs-1) : set_GRB NeoPixel + L! ; \ Set all LEDs to GRB \ ( n1 -- ) n1:G-R-B(Long) : set_all NeoPixel LEDs 0 do 2dup L! 4+ loop 2drop ; : demo h00_00_00 set_all c" ser_out LEDs NeoPixel _pixel_ring" 0 cogx NeoPixel Pixel LEDs 0 do 2dup L@ swap L! 4+ swap 4+ swap loop 2drop begin fkey? swap drop until 0 cogreset ; { \ Send 16-data[GRB:24bits] to NeoPixelRing \ ( n1 n2 n3 -- ) n1:serial-out port n2:LED count n3:address for LED-array fl build_BootOpt :rasm \ Set LED-array addrss to __start mov __start , $C_stTOS spop \ Set LED count to __ledcount mov __ledcount , $C_stTOS spop \ Set port to output and to lo mov __txmask , # 1 shl __txmask , $C_stTOS andn outa , __txmask or dira , __txmask spop __rgbmain \ Issue reset mov __bittimer , __reset add __bittimer , cnt waitcnt __bittimer , # 0 \ load LED-array addrss and LED count mov __current , __start mov __nleds , __ledcount __frameloop \ Get contents and add 4 to address rdlong __colorbits , __current add __current , # 4 \ Shift out long in colorbits to NeoPixelRing \ Shift 8bit __colorbits to left [00GGRRBB -> GGRRBB00] shl __colorbits , # 8 mov __nbits , # d24 __loop \ Shift left 1bit shl __colorbits , # 1 wc if_c mov __bittimer , __bit1hi if_nc mov __bittimer , __bit0hi or outa , __txmask add __bittimer , cnt if_c waitcnt __bittimer , __bit1lo if_nc waitcnt __bittimer , __bit0lo andn outa , __txmask waitcnt __bittimer , # 0 djnz __nbits , # __loop djnz __nleds , # __frameloop jmp # __rgbmain \ variables __start 0 __ledcount 0 __txmask 0 __bittimer 0 __current 0 __nleds 0 __colorbits 0 __nbits 0 \ constants \ 350nsec __bit0hi d28 \ 800nsec __bit0lo d64 \ 700nsec __bit1hi d56 \ 600nsec __bit1lo d48 \ 50usec __reset d4000 ;asm _pixel_ring }