fl fl { InifinityLED(38pcs) PropForth 5.5 2018/06/30 15:00:01 5V 3.3V 5V | | | 300ohm | | Propeller | | 300ohm WS2812B WS2812B WS2812B | ------ | -------- -------- -------- P0 ---- |2N7000| -----------|Din Dout|----- |Din Dout|-- ... ---|Din Dout| ------ -------- -------- -------- 2N7000 1st | | 2nd | | 38th | | | 5V-PS | 5V-PS | 5V-PS | | | GND ----------------------------------------------------------------------- GND(5V-PS) WS2812 Logic'0' Hi:400ns Lo:850ns Logic'1' Hi:800ns Lo:450ns } \ =========================================================================== \ Constants \ =========================================================================== \ serial pin to NeoPixelRing 0 wconstant ser_out \ LED count d38 wconstant LEDs \ color table [RR_GG_BB] variable color_table -4 allot h00_00_00 l, \ OFF h00_00_00 l, \ BLACK hFF_00_00 l, \ RED h00_FF_00 l, \ GREEN h00_00_FF l, \ BLUE hFF_FF_FF l, \ WHITE h00_FF_FF l, \ CYAN hFF_00_FF l, \ MAGENTA hFF_FF_00 l, \ YELLOW h7F_FF_00 l, \ CHARTREUSE hFF_60_00 l, \ ORANGE h7F_FF_D4 l, \ AQUAMARINE hFF_5F_5F l, \ PINK h3F_E0_C0 l, \ TURQUOISE hC8_FF_FF l, \ REALWHITE h3F_00_7F l, \ INDIGO hBF_7F_BF l, \ VIOLET h32_00_10 l, \ MAROON h0E_06_00 l, \ BROWN hDC_28_3C l, \ CRIMSON h8C_00_FF l, \ PURPLE \ =========================================================================== \ Variables \ =========================================================================== \ LED-array for NeoPixelRing (64bytes:4bytes/1LED) variable NeoPixel LEDs 4 * 4- allot wvariable base wvariable index \ =========================================================================== \ Main \ =========================================================================== \ Send LEDs-data[GRB:24bits] to infinityLED \ ( n1 n2 n3 -- ) n1:serial-out port n2:LED count n3:address for LED-array lockdict create _WS2812B 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, z1SyLI[ l, z2Wi][w l, z20i]ak l, z3ry]W0 l, z2Wi]fk l, z2Wi]nl l, z8i]vo l, z20y]b4 l, zWy]r8 l, z2Wya0O l, z1YVa07 l, z[d]vr l, z\y]r1 l, z2Wf][u l, z2WZ][s l, z1[ixnm l, z20i]ak l, z3rf][v l, z3rZ][t l, z1bixnm l, z3ry]W0 l, z3[ya4Z l, z3[y]nV l, z1SV04Q l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, 0 l, zN l, ze l, zn l, zF l, zxW l, freedict \ Pack R-G-B byte to Long \ ( n1 n2 n3 -- n4 ) n1:R[byte] n2:G[byte] n3:B[byte] n4:R-G-B [Long] : color swap 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[byte] n2:G[byte] n3:B[byte] n4:level[0 to 255] n5:R-G-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 * d255 / >r \ ( n1 n2 n4 ) dup \ ( n1 n2 n4 n4 ) rot * d255 / >r \ ( n1 n4 ) * d255 / r> r> \ ( n1' n2' n3' ) color \ ( n5 ) then then ; \ Set R-G-B[Long] value to position inside NeoPixel array \ R-G-B is packed Long in form hRR_GG_BB \ ( n1 n2 -- ) n1:R-G-B(Long) n2:position (0 to LEDs-1) : setPos 4 * NeoPixel + L! ; \ Write rgb elements to position in NeoPixel \ r, g, and b are byte values, 0 to 255 \ ( n1 n2 n3 n4 -- ) n1:position[0 to LEDs-1] n2:R[byte] n3:G[byte] n4:B[byte] : setRGB color swap setPos ; \ Fills from 1st to last position with rgb \ rgb is packed long in form hRR_GG_BB \ ( n1 n2 n3 -- ) n1:R-G-B(Long) n2:last(1 to 15) n3:1st( 0 to 14) : rgbFill 2dup > if swap 1+ swap do dup i 4 u* NeoPixel + L! loop drop else 3drop then ; \ Set all LEDs to RGB \ rgb is packed long in form hRR_GG_BB \ ( n1 -- ) n1:R-G-B(Long) : setAll LEDs 1- 0 rgbFill ; \ Display color-table[from address of color-table to index of color-table] and repeat n3-times from 0 to 15 on NeoPixelRing \ ( n1 n2 n3 -- ) n1:delay[msec] n2:address of color-table n3:index of color-table : colorChase dup index W! 0 do \ ( n1 n2 ) i base W! LEDs 0 do dup \ ( n1 n2 n2 ) base W@ 4 * + \ ( n1 n2 n2+base*4) L@ \ ( n1 n2 RGB ) i setPos \ Writes rgb elements to position in NeoPixel base W@ 1+ dup index W@ = \ Check if base is equal to index if drop 0 base W! \ back to original base else base W! \ next base then over delms \ ( n1 n2 ) loop loop 2drop ; \ Sequentially fills strip with color rgb \ ( n1 n2 -- ) n1:delay[msec] n2:R-G-B(Long) : colorWipe LEDs 0 do 2dup \ ( n1 n2 n1 n2 ) i setPos \ ( n1 n2 n1 ) delms loop 2drop ; \ Creates color from 0 to 255 color-position input \ ( n1 -- n2 ) n1:color_position n2:R-G-B[Long] : wheel dup d85 < if 3 * dup \ ( color_position*3 color_position*3 ) d255 swap - \ ( color_position*3 255-color_position*3 ) swap 0 \ ( 255-color_position*3 color_position*3 0 ) = (R G B) else dup d170 < if d85 - 3 * \ ( [color_position-85]*3 ) 0 swap \ ( 0 [color_position-85]*3 ) dup \ ( 0 [color_position-85]*3 [color_position-85]*3 ) d255 swap - \ ( 0 [color_position-85]*3 255-[color_position-85]*3 ) swap \ ( 0 255-[color_position-85]*3 [color_position-85]*3 ) = (R G B) else d170 - 3 * \ ( [color-position-170]*3 ) dup \ ( [color-position-170]*3 [color-position-170]*3 ) 0 swap \ ( [color-position-170]*3 0 [color-position-170]*3 ) d255 swap - \ ( [color-position-170]*3 0 255- [color-position-170]*3 ) = ( R G B ) thens color \ ( R-G-B[Long] ) ; \ Creates color from 0 to 255 color-position input \ colors transition r->g->b back to r \ level is brightness, 0 to 255 \ ( n1 n2 -- n3 ) n1:color-position n2:level n3:R-G-B[Long] : wheelx >r \ Push level wheel \ ( R-G-B[Long] ) dup d16 rshift swap dup 8 rshift hFF and swap hFF and r> colorx \ ( R-G-B[Long] ) ; \ ( n1 -- ) n1:delay[msec] : rainbow d255 0 do dup LEDs 0 do j i + hFF and wheel i \ ( R-G-B[Long] (0 to LEDs-1) ) setPos loop delms loop drop ; : demo 0 setAll c" ser_out LEDs NeoPixel _WS2812B" 0 cogx d100 delms d100 color_table 8 + 6 colorChase d500 delms d100 color_table 8 + L@ colorWipe d500 delms d100 color_table L@ colorWipe d500 delms d255 0 do i d128 wheelx i d38 u/mod drop setPos d100 delms loop d500 delms d20 rainbow 0 setAll d10 delms 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 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 ror __colorbits , # 8 mov __nbits , # d24 __loop \ Shift __colorbits to left when nbits is 24,16,8 test __nbits , # 7 wz \ if yes, modify colorbits if_z rol __colorbits , __nbits \ MSB --> Carry rol __colorbits , # 1 wc if_c mov __bittimer , __bit1hi if_nc mov __bittimer , __bit0hi andn dira , __txmask add __bittimer , cnt if_c waitcnt __bittimer , __bit1lo if_nc waitcnt __bittimer , __bit0lo or dira , __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 \ 400nsec __bit0hi d23 \ 850nsec __bit0lo d43 \ 800nsec __bit1hi d52 \ 450nsec __bit1lo d15 \ 50usec __reset d4000 ;asm _WS2812B }