fl fl { 7Segment LED with WS2812B(15pcs) PropForth 5.5 2014/10/04 14:48:06 a(bit7) --------- f(bit2) | | b(bit6) | g(bit1) | --------- e(bit3) | | c(bit5) | | --------- * dp(bit0) d(bit4) a/b/c/d/e/f/g segment have 2pcs of WS2812B. dp-segment has 1pc of WS2812B 3.3V 5V | | | | Propeller 2N7000 | 10k ----------------- | P0 -----|Source Gate Drain|---| ----------------- | | --------- \ | DI | | GND---|Vss Vdd|---5V |dp | DO | | --------- / --------------- | \ | | \ --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- | | --------- | | |g | | |c --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- / --------- / | \ | | \ --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- | | --------- | | |f | | |b --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- / --------- / | \ | | \ --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- | | --------- | | |e | | |a --------- | | --------- | | DI | | | | DI | | GND---|Vss Vdd|---5V | | GND---|Vss Vdd|---5V | | DO | | | | DO | | --------- / --------- / | \ | --------- | | | DI | | | GND---|Vss Vdd|---5V | | | DO | | | --------- | | | |d | --------- | | | DI | | | GND---|Vss Vdd|---5V | | | DO | | | --------- / | | | ----------------------- } \ =========================================================================== \ Variables \ =========================================================================== \ LED-array for 7SegmentLED (60bytes:4bytes/1LED) variable 7SEG d60 allot \ Display-data for 7SegmentLED [0 1 2 3 4 5 6 7 8 9 a b c d E F] wvariable num_tbl -2 allot hFC c, h60 c, hDA c, hF2 c, h66 c, hB6 c, hBE c, hE4 c, hFE c, hF6 c, hFA c, h3E c, h1A c, h7A c, h9E c, h8E c, \ offset of a-segment for 7SementLED buffer wvariable offset \ =========================================================================== \ Constants \ =========================================================================== \ serial pin to NeoPixelRing 0 wconstant ser_out \ LED count d15 wconstant LEDs \ offset of a-segment d52 wconstant a_seg \ color table [RR_GG_BB] variable color_tbl -4 allot 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 \ =========================================================================== \ Main \ =========================================================================== \ Send LEDs-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, h140 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2Wi]RB l, z1SyLI[ l, z2Wi]ZB l, z1SyLI[ l, z2Wy]b1 l, zfi]eB l, z1[ix[o l, z1bixno l, z1SyLI[ l, z2Wi]ny l, z20i]qk l, z3ry]j0 l, z2Wi]vm l, z2Wia4n l, z8iaCq l, z20y]r4 l, zWya88 l, z2WyaGO l, z1YVaG7 l, z[daCt l, z\ya81 l, z2Wf]nw l, z2WZ]nu l, z1bix[o l, z20i]qk l, z3rf]nx l, z3rZ]nv l, z1[ix[o l, z3ry]j0 l, z3[yaK\ l, z3[ya4X 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[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 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 ; \ Clear all LEDs \ Store 0 in 7Segmant array \ ( -- ) : clr_7SEG 0 7SEG LEDs 0 do 2dup L! 4+ loop 2drop ; \ Set Packed R-G-B[Long] to dp inside 7SEG-buffer \ ( n1 -- ) n1:color value[Long] : set_dp 7SEG L! ; \ Get next segment buffer address : next_segment offset W@ 8 - offset W! ; \ Set Packed R-G-B[Long] to each segment[a b c d e f g] inside 7SEG-buffer \ ( n1 n2 n3 -- ) n1:color value[Long] n2:color value[Long] n3:offset of each segment : segment 7SEG + \ Get buffer-addr of segment dup rot swap \ ( n1 addr n2 addr ) L! \ ( n1 addr ) 4+ L! \ ( -- ) ; : demo clr_7SEG \ Clear 7SegmentLED buffer c" ser_out LEDs 7SEG _pixel_ring" 0 cogx d100 delms \ === 1Segment(2LED) has same color. (Only dp is 1LED) === \ Display 1-segment by 1-segment a_seg offset W! \ Set a-segment offset color_tbl 7 0 do dup L@ dup offset W@ segment \ Set color data to 1-segment 4+ \ next color-table next_segment d500 delms clr_7SEG loop L@ set_dp d500 delms clr_7SEG \ Display number[0 .. F] on 7SEG-LED color_tbl d16 0 do a_seg offset W! \ Set a-segment offset num_tbl i + C@ h80 \ ( color_tbl num_data h80 ) 7 0 do 2dup and \ ( color_tbl num_data h80 1/0 ) if over L@ dup offset W@ segment \ Set each segment to color else 0 0 offset W@ segment \ Clear each segment then next_segment \ next segment 1 rshift loop 2drop 4+ \ Next color_table d500 delms loop drop clr_7SEG \ === 1Segment(2LED) has different color. (Only dp is 1LED) === \ Display 1-segment by 1-segment a_seg offset W! \ Set a-segment offset color_tbl 7 0 do dup dup L@ swap 4+ L@ swap offset W@ segment \ Set color data to 1-segment 8 + \ next color-table next_segment d500 delms clr_7SEG loop L@ set_dp d500 delms \ Display number[0 .. F] on 7SEG-LED color_tbl d16 0 do a_seg offset W! \ Set a-segment offset num_tbl i + C@ h80 \ ( color_tbl num_data h80 ) 7 0 do 2dup and \ ( color_tbl num_data h80 1/0 ) if 2 ST@ dup \ ( color_tbl num_data color_tbl color_tbl ) L@ swap 4+ L@ swap offset W@ segment \ Set each segment to color else 0 0 offset W@ segment \ Clear each segment then next_segment \ next segment rot \ ( num_data h80 color_tbl ) 8 + dup color_tbl d80 + = if drop color_tbl then rot2 \ ( color_tbl num_data h80 ) 1 rshift loop 2drop 8 + \ Next color_table dup color_tbl d80 + = if drop color_tbl then d500 delms loop drop clr_7SEG \ Clear 7SegmentLED buffer d100 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 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 ror __colorbits , # 8 mov __nbits , # d24 __loop \ Check if 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 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 }