PDA

View Full Version : Multiple GPIO input with the same timer



jeanclaudej971
May 2nd, 2017, 09:43 PM
Hello
I found this script used to detect a lighted TV or nipple.


raspi = require("raspi")

raspi.export( 24 )
raspi.direction( 24, false )

rpidoor = {}
rpidoor.enabled = false

print("RPI IO Enabled.")

rpidoor.timer = timer.new( 100, function()

local pin = raspi.read( 24 ) ~= 0

-- disable this line once it all works.
print("Periodic DOOR Check", pin)

if pin ~= rpidoor.enabled then
if pin then
gir.triggerEvent("DOOR open", 18, Promixis.Event.MOD_ON, payload)
else
gir.triggerEvent("DOOR closed", 18, Promixis.Event.MOD_ON, payload)
end
rpidoor.enabled = pin
end



end)

rpidoor.timer:start()



It works perfectly, but I would like to use it to scan several GPIO inputs with open door detectors or close with the same time delay so as not to saturate the R pie.
Would it be possible to export and give direction to several entries at the same time?
Could you help me edit the script for GPIO24 and 25 for example?

regards
Jean Claude

Ron
May 2nd, 2017, 09:51 PM
inside the timer just check all the pins you need checked. Should be OK. Keep an eye on your CPU usage.

jeanclaudej971
May 3rd, 2017, 05:48 PM
Hello Ron


Thank you for your answer!;)

I try with Scripte:

raspi = require("raspi")

raspi.export( 24 )
raspi.direction( 24, false )
raspi.export( 25 )
raspi.direction( 25, false )



rpiinter = {}
rpiinter.enabled = false

print("RPI IO Enabled.")

rpiinter.timer = timer.new( 200, function()

local PIN24 = raspi.read( 24 ) ~= 0


-- disable this line once it all works.
print("SCANNE INTER")

if PIN24 ~= rpiinter.enabled then
if PIN24 then
gir.triggerEvent("INTER 24 on", 18, Promixis.Event.MOD_ON, payload)
else
gir.triggerEvent("INTER 24 off", 18, Promixis.Event.MOD_ON, payload)
end
rpiinter.enabled = PIN24
end

local PIN25 = raspi.read( 25 ) ~= 0

if PIN25 ~= rpiinter.enabled then
if PIN25 then
gir.triggerEvent("INTER 25 on", 18, Promixis.Event.MOD_ON, payload)
else
gir.triggerEvent("INTER 25 off", 18, Promixis.Event.MOD_ON, payload)
end
rpiinter.enabled = PIN25
end



end)

rpiinter.timer:start()



It works but not as I wish, because I get both events well but pressing button 24 I receive "INTER 24 on" and releasing it "INTER 25 off" and vice versa.
I do not yet master LUA enough to figure out what's going on. I would like to receive the Events of each support distinctly "24 on, off" and "25 on off" always with the same timing.

can you help me ?

Regards

Jean Claude