Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rainbowize()
- green = {0, 61, 127, 193, 255, 255, 255, 255, 255, 255, 255, 255, 255, 193, 127, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- red = {255, 255, 255, 255, 255, 183, 127, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 127, 193, 255, 255, 255, 255, 255}
- blue = {0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 127, 193, 255, 255, 255, 255, 255, 255, 255, 255, 255, 193, 127, 61, 0}
- rainbow_i = (rainbow_i % table.getn(green))+1
- return red[rainbow_i], green[rainbow_i], blue[rainbow_i]
- end
- function dupa()
- ws2812.init()
- rainbow_i = 0
- local dir, i, buffer = 0, 0, ws2812.newBuffer(300, 3);
- buffer:fill(0, 0, 0);
- tmr.create():alarm(25, 1, function()
- if (dir==0) then
- i = i + 1
- if (i == buffer:size()) then
- dir=1
- end
- else
- i = i - 1
- if (i == 0) then
- dir=0
- end
- end
- buffer:mix(220, buffer)
- r,g,b = rainbowize()
- buffer:set(i % buffer:size() + 1, r, g, b)
- buffer:set((2 * i) % buffer:size() + 1, r, g, b)
- ws2812.write(buffer)
- end)
- end
- dupa()
Advertisement
Add Comment
Please, Sign In to add comment