ESP8266 with WS2812B Light Strip

From Playful Exploration
Jump to navigation Jump to search


Simple Light Play

https://www.youtube.com/watch?v=FFL2lL9ni2I

This demo code can run from the lua command line or from a lua file e.g. init.lua.

Rotate light while changing color:

b=string.char(
255,255,  0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,
255,  0,  0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,
  0,255,  0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,
  0,255,255, 0,0,0, 0,0,0, 0,0,0, 0,0,0,
  0,  0,255, 0,0,0, 0,0,0, 0,0,0, 0,0,0
)
tmr.alarm(0, 100, tmr.ALARM_AUTO, function()
  b=b:sub(4)..b:sub(0,3) -- left-rotate the string by 3 i.e. the rgb values of one led
  ws2812.write(3,b)
end)

Soft-dim light up, down, repeat:

a=0   -- brightness
ad=2  -- change per step
tmr.alarm(0, 10, tmr.ALARM_AUTO, function()
  b=string.char(0,0,255-a,0,0,a, 255-a,0,0,a,0,0, 0,255-a,0,0,a,0):rep(5)
  ws2812.write(3,b)
  a=a+ad if a<0 or a>255 then
    ad=ad*-1
    a=a+ad
  end
end)