Post your best Lua script examples here

User avatar
By la3bna
#30183 Im trying to mak a small web page thet controls x number of ws2812(neoPixels)

I want to be able to change the specific pixel and just the one.

In arduino I would use an array to choose the ppixel, or just select the one with the neopixel liberary.

Code: Select allcolor  = string.char(r1,g1,b1,r2,g2,b2,r3,g3,b3)

ws2812.writergb(pixelPin, color)


I have been trying to use tabel as well but No luck.
User avatar
By Luc Volders
#30402 Here is the code you can use.

Code: Select all-- define the colors
o=string.char(0,0,0)    -- off
r=string.char(100,0,0)  -- red
g=string.char(0,100,0)  -- green
b=string.char(0,0,100)  -- blue
-- make an array n with as many elements
--as there are neopixels
n={} -- leaving it open makes the array dynamic
-- fill the array with r,g,b values in this example 7 neopixels
for i=1,3 do
     n[i] = b
end
n[4] = r
for i=5,7 do
     n[i] = g
end
--set neopixels to rgb values
ws2812.writergb(3,n[1]..n[2]..n[3]..n[4]..n[5]..n[6]..n[7])


Works flawlessly with my ESP8266-01

Luc