commit
This commit is contained in:
parent
89886ac0ea
commit
52c5047699
6 changed files with 199 additions and 11 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue