Open deennoo opened 8 years ago
hi again
Why i want to use ws2812b ? because i already got one who left from another project and i want to recycle it.
i start working on a ws2812b led strip with your milight.lua sketch.
Got 2 succes and 1 probleme :
i got succes by turn on and off all my pixel.
Got probleme by changing color :
Basicly to set a color to a single ws2812b we have to write :
leds_grb = string.char(g,r,b) ws2812.write(2, leds_grb)
Where 2 is the data pin and leds_grb is the color
to set this color to the whole strip :
leds_grb = string.char(g,r,b) ws2812.write(2, leds_grb:rep(x))
rep is the repeat fonction x is the pixel number
As i'm a beginner on LUA script, i got a probleme by linking
leds_grb and r, g, b = hslToRgb(current_hue, current_sat, current_lum)
on
`if act then r, g, b = hslToRgb(current_hue, current_sat, current_lum)
pwm.setduty(r_pin, r)
pwm.setduty(g_pin, g)
pwm.setduty(b_pin, b)
end`
Can you help me please ?
well, i have no exp with ws2812, but if i understood you correctly, it would be something like:
if act then
r, g, b = hslToRgb(current_hue, current_sat, current_lum)
leds_grb = string.char(g, r, b)
ws2812.write(2, leds_grb:rep(x))
end
btw, here are some nice examples https://github.com/geekscape/nodemcu_esp8266/blob/master/examples/ws2812.lua
thanks for your time
i already try this and igot this error :
-- return error : PANIC: unprotected error in call to Lua API (milight.lua:94: bad argument #1 to 'char' (invalid value)) --PANIC: unprotected error in call to Lua API (bad argument #2 (number expected, got no value)) --PANIC: unprotected error in call to Lua API (bad argument #3 (number expected, got no value))
My Git : https://github.com/deennoo/ESP8266-ws2812b/tree/nodemcu
ok, i think i see where is the problem.
Color coefficients for r, g, b are scaled to value 1023, unlike usual 255. (nodemcu has 10-bit resolution for PWM). This is way outside of the domain of string.char()
.
So to fix try to changing this line:
return math.floor(r * 1023 + 0.5), math.floor(g * 1023 + 0.5), math.floor(b * 1023 + 0.5)
to this one:
return math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(b * 255 + 0.5)
Bingo !!! it works !!
Using Domoticz (home automation app, device is set as a rgb style and just on/off switch), and android app : wifi controller 2.0
next step ? lum and sat !
Edit : Lum/brightness works, just need to find a way to get sat... Edit 2 : sat is working but responding to disco mode+ and disco mode - will investigate....
Thank again for your help !!
Hi there,
Thanks for your work.
I try it and it run well !
I wondering if it can be modified for ws2812b led strip ? If yes which part of milight.lua have to be change ?
Thx