Something along the lines of the code below is what I'd like to do. However, it won't work because the function returns (with no value) before the timer callback runs. Now I could do this by using tmr.delay(), but I'd like to avoid that if at all possible, since these wait times can be quite slow in some cases.
Anyone have any neat ideas on how to hold off returning a value until the sensor conversion is complete?
function returnSensor()
querySensor()
tmr.alarm(0, 100, tmr.ALARM_SINGLE, function()
val = querySensor()
return val
end)
end