diff --git a/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua index 9ce7bff..828e65d 100644 --- a/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua +++ b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua @@ -2,34 +2,40 @@ -- tout sur la couleur: https://www.w3schools.com/colors/default.asp -- roue des couleurs: https://iro.js.org/?ref=oldsite -print("\n a_guirlande.lua zf181216.0020 \n") +print("\n a_guirlande.lua zf181216.0131 \n") znbleds_max=300 znbleds=300 -zstep=1 +zstep=5 zpower=1 +zleds={} +zledinc={} + function RGB_clear() ws2812.init() buffer = ws2812.newBuffer(znbleds_max, 3) - buffer_reg = ws2812.newBuffer(znbleds_max, 3) buffer:fill(0, 0, 0) ws2812.write(buffer) end +function zleds_init() + for i=1, znbleds, zstep do + zleds[i]=0 + end +end + function zfaderando() for i=1, znbleds, zstep do - r, g, b=buffer:get(i) - r=r+zledinc[i] g=g+zledinc[i] b=b+zledinc[i] - if r >255 then - r=255 g=255 b=255 + zleds[i]=zleds[i]+zledinc[i] + if zleds[i] >255 then + zleds[i]=255 zledinc[i]=zrando() end - if r <0 then - r=0 g=0 b=0 + if zleds[i] <0 then + zleds[i]=0 zledinc[i]=zrando() end - buffer:set(i, r, g, b) end end @@ -44,12 +50,17 @@ function zrando() end function zincfill() - zledinc={} for i=1, znbleds, zstep do zledinc[i]=zrando() end end +function zbufferfill() + for i=1, znbleds, zstep do + buffer:set(i, zleds[i], zleds[i], zleds[i]) + end +end + function zeffect_stop() tmr.unregister(effect_tmr1) RGB_clear() @@ -57,13 +68,20 @@ end function zeffect_start() effect_tmr1=tmr.create() - tmr.alarm(effect_tmr1, 200, tmr.ALARM_AUTO, function() + tmr.alarm(effect_tmr1, 300, tmr.ALARM_AUTO, function() zfaderando() + zbufferfill() zpower_reg() - ws2812.write(buffer_reg) + ws2812.write(buffer) end) end +function zfade(f) + for i=1, znbleds, zstep do + r, g, b=buffer:get(i) + buffer:set(i, r*f, g*f, b*f) + end +end function zpower_reg() psu_current_ma = 1000 @@ -78,16 +96,19 @@ function zpower_reg() -- print(led_sum) p = buffer:power() --- print(p,led_sum) if p > led_sum then - buffer_reg:mix(256 * led_sum / p, buffer) -- power is now limited - else - buffer_reg:mix(255, buffer) + f=led_sum/p +-- print("f: ",f) +-- print(p) + zfade(f) +-- p = buffer:power() +-- print(p) end end RGB_clear() +zleds_init() zincfill() zeffect_start()