- Tue Feb 24, 2015 7:22 pm
#10636
Argument 3 is expecting a callback function, so unless your file is returning a function, you need to wrap it in a function:
Code: Select allgpio.trig(3,"high",function() dofile("interupt.lua") end)
Alternatively:
Code: Select allgpio.trig(3,"high",loadfile("interupt.lua"))
The first version reparses and compiles the file every time the interrupt happens, but frees the memory when it is done, while the second compiles the file to a function once and re-executes it each time, but keeps the compiled function in memory. So use the top version to optimize memory and the bottom for speed.
Also, tmr.delay is a busy loop, which may not give lua an opportunity to fire the interrupt routine (I'm not sure how hardware interrupts are handled in a single-threaded environment - you usually want to get in and out fast though). You may need to switch to tnr.alarm. It takes a callback function as well, which you would put the second led toggle inside of.
Finally, you don't need to put the trig in a loop: set it once and it should trigger every time the condition is met.
Last edited by dpwhittaker on Tue Feb 24, 2015 7:31 pm, edited 1 time in total.