code-lua-iot/neopixel.lua
2024-10-23 20:08:41 +02:00

80 lines
1.6 KiB
Lua

-- écrit le 12/10/2024 par Lukian Leizour
function feux()
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO18, 8)
while true do
neo:setPixel(7, 255, 0, 0)
neo:update()
tmr.delayms(3000)
neo:setPixel(7, 0, 0, 0)
neo:setPixel(5, 0, 255, 0)
neo:update()
tmr.delayms(3000)
neo:setPixel(5, 0, 0, 0)
neo:setPixel(6, 255, 255, 0)
neo:update()
tmr.delayms(1000)
neo:setPixel(6, 0, 0, 0)
end
end
function arc()
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO18, 8)
for i=0,7 do
r, g, b = wheelRGB((255*i) // 8)
neo:setPixel(i, r//10, g//10, b//10)
end
neo:update()
end
function arc_move()
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO18, 8)
pixel = 0
direction = 0
while true do
r, g, b = wheelRGB((255*pixel) // 8)
neo:setPixel(pixel, r, g, b)
neo:update()
tmr.delayms(100)
neo:setPixel(pixel, r//10, g//10, b//10)
if (direction == 0) then
if (pixel == 7) then
direction = 1; pixel = 6
else
pixel = pixel + 1
end
else
if (pixel == 0) then
direction = 0; pixel = 1
else
pixel = pixel - 1
end
end
end
end
function fete()
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO18, 8)
while true do
r, g, b = wheelRGB(math.random(0, 255))
neo:setPixel(math.random(0, 7), r, g, b)
neo:update()
tmr.delayms(50)
end
end
function dice() -- on note que le dé renvoie toujours la même valeur étant donné qu'il est appelé au démarage et que math.random() a comme seed l'uptime de l'ESP32
for i=0,math.random(0, 7) do
r, g, b = wheelRGB((255*i) // 8)
neo:setPixel(i, r, g, b)
neo:update()
end
end