I have this script to check whether any of the relays are enabled.
function update()
gcs:send_text(0, "GPIO READ")
for i=0, 6 do
if relay:get(i) == true or relay:get(i) > 0 then
gcs:send_text(0, string.format("Relay %s works!", tostring(i)))
end
gcs:send_text(0, string.format("Relay %s: %s - %s", tostring(i), tostring(relay:get(i)), tostring(relay:enabled(i))))
end
return update, 5000
end
return update()
Even though i toggle the relays like this:
My lua script can’t detect it. I get the following output:
the two true statements indicate that the ports are enabled. but yet they are always 0. I also tried arming the thing but it didn’t make difference.
-- desc
---@param instance integer
function relay:toggle(instance) end
-- desc
---@param instance integer
---@return boolean
function relay:enabled(instance) end
-- return state of a relay
---@param instance integer
---@return integer
function relay:get(instance) end
-- desc
---@param instance integer
function relay:off(instance) end
-- desc
---@param instance integer
function relay:on(instance) end
function update()
gcs:send_text(0, "GPIO READ")
for i=0, 6 do
if relay:get(i) == 1 then
gcs:send_text(0, string.format("Relay %s works!", tostring(i)))
end
gcs:send_text(0, string.format("Relay %s: %s - %s", tostring(i), tostring(relay:get(i)), tostring(relay:enabled(i))))
end
return update, 5000
end
return update()
It never says it works, the result of relay:get(i) is always 0.
More investigation:
It works perfectly on sim with 4.4 plane and 4.5.x plane. However it doesn’t work on an orange cube.
Tried another orange cube, this is working. There is something wrong with my other orange cube, I will update my findings here.