commit
This commit is contained in:
parent
89886ac0ea
commit
52c5047699
6 changed files with 199 additions and 11 deletions
|
@ -1,7 +1,10 @@
|
|||
-- charge le fichier principal
|
||||
dofile("main.lua")
|
||||
dofile("neopixel.lua")
|
||||
dofile("encoder.lua")
|
||||
|
||||
-- affiche la température du CPU
|
||||
printTemp()
|
||||
|
||||
|
||||
-- affiche le résultat du dé sur le neopixel
|
||||
-- dice()
|
||||
|
|
41
encoder.lua
Normal file
41
encoder.lua
Normal file
|
@ -0,0 +1,41 @@
|
|||
-- écrit par Lukian Leizour le 12/10/2024
|
||||
|
||||
function print_pos()
|
||||
enc = encoder.attach(pio.GPIO18, pio.GPIO19, pio.GPIO21, function(dir, counter, button)
|
||||
print(dir, counter, button)
|
||||
end)
|
||||
end
|
||||
|
||||
function scroll()
|
||||
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO22, 8)
|
||||
pos = 0
|
||||
|
||||
enc = encoder.attach(pio.GPIO18, pio.GPIO19, pio.GPIO21, function(dir, counter, button)
|
||||
neo:setPixel(pos, 0, 0, 0)
|
||||
if (dir == 1) then pos = (pos + 1) % 8
|
||||
elseif (dir == -1) then pos = (pos - 1) % 8 end
|
||||
r, g, b = wheelRGB(math.random(0, 255))
|
||||
neo:setPixel(pos, r//10, g//10, b//10)
|
||||
neo:update()
|
||||
end)
|
||||
end
|
||||
|
||||
function led_on_off()
|
||||
on = false
|
||||
enc = encoder.attach(pio.GPIO18, pio.GPIO19, pio.GPIO21, function(dir, counter, button)
|
||||
if button == 1 then on = not on end
|
||||
if on then pinon(pio.GPIO2) else pinoff(pio.GPIO2) end
|
||||
end)
|
||||
end
|
||||
|
||||
function led_speed()
|
||||
device = pwm.attach(pio.GPIO2, 1, 0.5)
|
||||
device:start()
|
||||
pos = 1
|
||||
|
||||
enc = encoder.attach(pio.GPIO18, pio.GPIO19, pio.GPIO21, function(dir, counter, button)
|
||||
if (dir == 1) then pos = pos + 1
|
||||
elseif (dir == -1 and pos > 1) then pos = (pos - 1) end
|
||||
device:setfreq(pos)
|
||||
end)
|
||||
end
|
2
main.lua
2
main.lua
|
@ -1,5 +1,7 @@
|
|||
-- charge les fonctions du fichier out.lua
|
||||
dofile("out.lua")
|
||||
dofile("neopixel.lua")
|
||||
dofile("encoder.lua")
|
||||
|
||||
-- fonction permettant d'afficher la température du CPU
|
||||
function printTemp()
|
||||
|
|
93
neopixel.lua
Normal file
93
neopixel.lua
Normal file
|
@ -0,0 +1,93 @@
|
|||
-- é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 wheelRGB(pos)
|
||||
pos = 255 - pos
|
||||
if (pos < 85) then
|
||||
return 255 - pos * 3, 0, pos * 3
|
||||
elseif (pos < 170) then
|
||||
pos = pos - 85
|
||||
return 0, pos * 3, 255 - pos * 3
|
||||
else
|
||||
pos = pos - 170
|
||||
return pos * 3, 255 - pos * 3, 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
|
34
out.lua
34
out.lua
|
@ -57,21 +57,35 @@ function smooth()
|
|||
tmr.delayms(200)
|
||||
i = i - 0.05
|
||||
end
|
||||
device:stop()²
|
||||
device:stop()
|
||||
end
|
||||
|
||||
red:start()
|
||||
green:start()
|
||||
blue:start()
|
||||
function rgb(r, g, b)
|
||||
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()
|
||||
|
||||
tmr.delayms(5000)
|
||||
|
||||
red:stop()
|
||||
green:stop()
|
||||
blue:stop()
|
||||
red:stop(); red:detach()
|
||||
green:stop(); green:detach()
|
||||
blue:stop(); blue:detach()
|
||||
end
|
||||
|
||||
red:detach()
|
||||
green:detach()
|
||||
blue:detach()
|
||||
function allrgb()
|
||||
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()
|
||||
|
||||
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
|
||||
|
||||
red:stop(); red:detach()
|
||||
green:stop(); green:detach()
|
||||
blue:stop(); blue:detach()
|
||||
end
|
||||
|
||||
-- fonction permettant d'allumer un buzzer pendant un temps donné
|
||||
|
|
35
pwm.lua
Normal file
35
pwm.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
-- é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
|
Loading…
Add table
Add a link
Reference in a new issue