Can timers be used to create custom LED animations? | Intech Studio
💬 general Grid

Can timers be used to create custom LED animations?

0xdb
0xdb · · 5 replies

I was wondering if there's a way to create custom animations. Existing animations go all the range from min to max, 0-255. I'd like to configure those values so I can have animation intensity relative to my element's value.

Replies (5)

0xdb 0xdb ·

self-answering in case this is useful to others: yes, you totally can - I wrote a function to blink the led once when you are turning an encoder "past" it's min or max (0, 127)

0xdb 0xdb ·

the difference between mine and the provided led animation function is that it will work with value 0 by using beautify to do "true off" zero only to give this warning, and then it goes back to "dim" zero

0xdb 0xdb ·
image.png
0xdb 0xdb ·

blink_count = 3 corresponds to one isolated blink, not just toggling on and off - starts on, 1. off, 2. on, 3. off, back on

0xdb 0xdb ·

Code for saw function:

function lvb(num, v, b)
    led_color(num, 2, R, G, B, b)
    led_value(num, 2, v * 2)
end
function saw(e, n, t, i_min, i_max)
    local num = e:element_index()
    if i_max < i_min then
        i_max = i_min
    end
    local range = i_max - i_min
    local period = t / n
    local timer = math.max(30, math.min(math.floor(period / range), 60))
    local steps = period / timer
    local cur = e.saw_step / (steps > 1 and (steps - 1) or 1)
    local i = math.floor(i_min + (range * cur) + 0.5)
    if e.saw_state == 0 then
        e.saw_step = 0
        lvb(num, i_max, 0)
    else
        if e.saw_step == 0 then
            lvb(num, i, 1)
        else
            lvb(num, i, 0)
            if e.saw_step >= steps then
                e.saw_step = -1
            end
        end
        e.saw_step = e.saw_step + 1
        timer_start(num, timer)
    end
end
Discord

View on Discord

This post is from the Intech Studio Discord community.

Open thread →