This commit is contained in:
Lukian 2024-10-10 16:20:39 +02:00
parent 3613b81d71
commit 89886ac0ea

55
out.lua
View file

@ -23,16 +23,55 @@ function blink (pin, n, delay) -- pin : la patte de sortie; n : int, nombre d'it
end
end
function blink_pwm(pin, n, delay)
print(1 / (delay * 2 / 1000), 0.5)
device = pwm.attach(pin, math.floor(1 / (delay * 2 / 1000)), 0.5)
device:start()
tmr.delayms(n * delay)
device:stop()
-- fonction permettant de faire clignoter la led sur la pin 18 4 fois brièvement
function blink_pwm1()
device = pwm.attach(pio.GPIO18, 1, 0.2) -- 1Hz et 20% de signal "haut"
device:start() -- départ
tmr.delayms(4000) -- on attend que la led ait finit de clignoter
device:stop() -- on arrête le signal
device:detach() -- on se détache de la pin
end
function test(n, delay)
blink_pwm(pio.GPIO18, n, delay)
-- fonction permettant de faire clignoter la led sur la pin 18 4 fois longuement
function blink_pwm2()
device = pwm.attach(pio.GPIO18, 1, 0.8) -- 1Hz et 80% de signal "haut"
device:start() -- départ
tmr.delayms(4000) -- on attend que la led ait finit de clignoter
device:stop() -- on arrête le signal
device:detach() -- on se détache de la pin
end
-- fonction permettant d'allumer et étteindre progressivement une led sur la pin 18
function smooth()
device = pwm.attach(pio.GPIO18, 200, 0)
device:start()
i = 0
while i <= 1 do
device:setduty(i)
tmr.delayms(200)
i = i + 0.05
end
i = 1.
while i >= 0 do
device:setduty(i)
tmr.delayms(200)
i = i - 0.05
end
device:stop()²
red:start()
green:start()
blue:start()
tmr.delayms(5000)
red:stop()
green:stop()
blue:stop()
red:detach()
green:detach()
blue:detach()
end
-- fonction permettant d'allumer un buzzer pendant un temps donné