Results 1 to 3 of 3

Thread: Multiple GPIO input with the same timer

  1. #1

    Default Multiple GPIO input with the same timer

    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

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,541

    Default

    inside the timer just check all the pins you need checked. Should be OK. Keep an eye on your CPU usage.
    Ron
    No support through PM

  3. #3

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •