lua - How does the buffer from the ws2812b module work? -
this example taken ws2812 documentation:
ws2812.init() local i, buffer = 0, ws2812.newbuffer(300, 4); buffer:fill(0, 0, 0, 0); tmr.create():alarm(50, 1, function() = + 1 buffer:fade(2) buffer:set(i % buffer:size() + 1, 0, 0, 0, 255) ws2812.write(buffer) end)
first of tried translate more readable , since use rgb , not rgbw leds, removed w component:
local numberofleds = 300 local bytesperled = 3 -- (r, g , b) ws2812.init() local local buffer = 0 ws2812.newbuffer(numberofleds, bytesperled) buffer:fill(255, 255, 255) tmr.create():alarm(50, 1, function() -- repeat every 50 milliseconds = + 1 buffer:fade(2) buffer:set(i % buffer:size() + 1, 255, 255, 255) ws2812.write(buffer) end)
it doesn't make sense me, though. why buffer
have fill method? mean didn't set 0? buffer = 0
translating incorrectly?
original code said local i, buffer = 0, ws2812.newbuffer(...); ...
the original code equivalent to
local = 0 local buffer = ws2812.newbuffer(300, 4); buffer:fill(0, 0, 0, 0); tmr.create():alarm(50, 1, function()
in general,
local x,y,z = a,b,c
is equivalent to
local x = local y = b local z = c
see manual.
Comments
Post a Comment