I'm attempting to read a digital input (FIO0) into a Lua script.
local inpin = 2000
local instat = MB.R(2000, 0)
Later in the program, I print out variable instat and it's always at a value of 1.000000. When I toggle the physical input I can see it change from true to false on the Dashboard but print(instat) is always showing 1.000000.
Am I reading the digital input correctly? I searched the example code and didn't see any examples reading a digital input.
Thanks!
The "MB.R(2000, 0)" call is correct in that it reads from FIO0, but when you want a current reading, you need to call the MB.R function. If you only have the one:
local instat = MB.R(2000, 0)
And print instat throughout your code, it will have the one read value when MB.R was called.
For example, reading and displaying the FIO0 state every one second:
local instat = 0
LJ.IntervalConfig(0, 1000)
while true do
if LJ.CheckInterval(0) then
instat = MB.R(2000, 0) --Get current FIO0 state
print("FIO0 = ", instat)
end
end