Lua led blink not working as expected

Issue #2808 resolved
Garry George
created an issue

Here is the test code:

my_key = 0

function check_requests() if my_key == KEY.PLAY then -- blink test led_blink() -- 0nce msleep(5000) led_blink(5,200,200) msleep(5000) led_blink(10,200,200) end return true end

function test_key(k) my_key = k end

event.shoot_task = check_requests event.keypress = test_key


The error is that one only seems to get a single blink. Tested on EOSM and 5D3

Comments (2)

  1. Alex

    Nicer test script:

    -- LED blink test
    
    my_key = 0
    
    function check_requests()
        if my_key == KEY.PLAY then
            -- blink test led_blink() 
            task.yield(5000)
            led_blink(5,200,200)
            task.yield(5000)
            led_blink(10,200,200)
            -- if no key is pressed after PLAY, this will keep blinking, repeating the cycle
            -- exercise for the reader
        end
        return true
    end
    
    function test_key(k)
        my_key = k
    end
    
    event.shoot_task = check_requests
    event.keypress = test_key
    

    The biggest change is task.yield instead of msleep; this lets event.keypress run during the long delays. It will probably break in more complex scripts, so use with care.

  2. Log in to comment