code-lua-iot/pwm.lua
2024-10-12 21:53:58 +02:00

35 lines
No EOL
1.1 KiB
Lua

-- écrit le 12/10/2024 par Lukian Leizour
function rgb(r, g, b)
-- on attache et démarre les pins
red = pwm.attach(pio.GPIO21, 2000, r / 256); red:start()
green = pwm.attach(pio.GPIO19, 2000, g / 256); green:start()
blue = pwm.attach(pio.GPIO18, 2000, b / 256); blue:start()
-- on attend 5 secondes
tmr.delayms(5000)
-- on stoppe et détache les pins
red:stop(); red:detach()
green:stop(); green:detach()
blue:stop(); blue:detach()
end
function allrgb()
-- on attache et démarre les pins
red = pwm.attach(pio.GPIO21, 2000, 1.); red:start()
green = pwm.attach(pio.GPIO19, 2000, 0); green:start()
blue = pwm.attach(pio.GPIO18, 2000, 0); blue:start()
-- on boucle pour afficher toutes les couleurs RGB
for i=0,255,5 do green:setduty(i / 256); tmr.delayms(50) end
for i=255,0,-5 do red:setduty(i / 256); tmr.delayms(50) end
for i=0,255,5 do blue:setduty(i / 256); tmr.delayms(50) end
for i=255,0,-5 do green:setduty(i / 256); tmr.delayms(50) end
for i=0,255,5 do red:setduty(i / 256); tmr.delayms(50) end
-- on stoppe et détache les pins
red:stop(); red:detach()
green:stop(); green:detach()
blue:stop(); blue:detach()
end