Welcome to the Parallax Discussion Forums, sign-up to participate.
{ Prop2 WS2812 demo using smartpins Version 0.2 ozpropdev Feb 15th 2019 } sys_clk = 25_000_000 us = sys_clk / 1_000_000 ws2812_load = 51 * us _200ns = us * 200 / 1000 num_leds = 64 clk = 14 ws2812 = 15 dat org hubset #0 wrpin #%1_00101_0,#clk 'transition mode wxpin ##_200ns,#clk dirh #clk wrpin ##%1111 << 24 | %1_11100_0,#ws2812 'sync tx mode wxpin #%1_00000 | 23,#ws2812 dirh #ws2812 'build ws812 waveform data into lut for each byte 'e.g. byte $8c becomes %001_001_011_011_001_001_001_011 mov index,#0 build mov count,#8 'number of bits mov pa,index mov pb,#0 .loop testb pa,#7 wc shl pb,#3 or pb,#1 '0 = %100 (1/3 t) if_c or pb,#%10 '1 = %110 (2/3 t) shl pa,#1 djnz count,#.loop shl pb,#32-24 rev pb 'prepare for msb shifted first wrlut pb,index incmod index,#255 wz if_nz jmp #build getct time addct1 time,delay 'Main loop 'send data to ws2812 devices update_ws2812 loc ptra,#@led_buffer 'iitialize pointer mov leds,#num_leds next_led rdlong rgb,ptra++ 'get grb data mov count,#3 '3 * 8 bits next_color getbyte pb,rgb,#2 'get color byte shl rgb,#8 rdlut pa,pb 'convert to waveform wypin pa,#ws2812 'load sync tx with 24 bit waveform wypin #48,#clk 'start 48 clock transitions busy testp #clk wc 'wait for smartpin completion if_nc jmp #busy rdpin 0,#clk 'clear smartpin djnz count,#next_color djnz leds,#next_led waitx ##ws2812_load 'data low for >50Us 'shift led pattern in led buffer pollct1 wc if_nc jmp #update_ws2812 addct1 time,delay loc ptra,#@led_buffer loc ptrb,#@led_buffer+4 rdlong pb,ptra rep #2,#63 rdlong pa,ptrb++ wrlong pa,ptra++ wrlong pb,ptra jmp #update_ws2812 time long 0 delay long sys_clk / 20 count long 0 index long 0 rgb long 0 leds long 0 lut long 0 orgh $400 led_buffer long $00_1f_00_00[4] 'green long $00_00_1f_00[4] 'red long $00_00_00_1f[4] 'blue long $00_00_1f_1f[4] 'magenta long $00_1f_00_1f[4] 'cyan long $00_1f_1f_00[4] 'yellow long $00_1f_1f_1f[4] 'yehite long 0[4] long $00_1f_00_00[8] 'green long $00_00_1f_00[8] 'red long $00_00_00_1f[8] 'blue long $00_00_1f_1f[8] 'magenta
Comments
Enjoy!
Mike
A determined coder can write COBOL programs in any language. -- Author unknown.
Press any key to continue, any other key to quit
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
Smartpins make this so easy. A single cog can control a huge amount of leds.
BTW this is running in RCFAST mode with no problems.