element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum inhibit buttons whilst running script?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 39 replies
  • Answers 7 answers
  • Subscribers 709 subscribers
  • Views 4763 views
  • Users 0 members are here
  • python
  • raspberry_pi
  • raspberry pi
  • piface
Related

inhibit buttons whilst running script?

brew
brew over 10 years ago

Hi there I'm trying to use my Raspberry Pi 1B and PiFace to run a little interactive museum exhibition.

 

Process is Pi is in standby, Standby.py runs from rc.local Relay 1 is closed as this is the main light in the room,

Button Press (SW1) initiates the show

GoShow.py runs, this closes a number of replays which change the lights in the space and trigger a media player for the video the Pi plays a audio file.

 

I want to inhibit the button when GoShow is active, I've tried to 'de-listen' under the GoShow.py but no luck.

 

https://github.com/Brewj/Event-Trigger

 

Anyone any ideas?

 

Cheers

Brew

  • Sign in to reply
  • Cancel
  • clem57
    0 clem57 over 10 years ago

    Easy. when the show starts save a file like start_show. When the show ends delete file start_show. If Standby.py se file start_show, do nothing.

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jack.chaney56
    0 jack.chaney56 over 10 years ago

    Seems the thing you are looking for is what is called a semaphore. Which is an OS feature.  Simply put, a semaphore is a switch that is tested for state, prior to an activity.  If the state is available, the task runs, if the state is not available, the task sleeps until the state becomes available.  The OS usually manages semaphore operation by putting a task in a "sleep" state when a semaphore is not available, and waking the task back up when the state is changed.

     

    For your case, it could be something as simple as a flag that is examined in the interrupt (SW1 input). If the switch was off, it turns it on, and starts the presentation, if the switch is on, the event is ignored. The presentation routine sets the switch off upon completion.  A "counter" can also be implemented for queued SW1 inputs, so the presentation will repeat if more than one SW1 input is received, so the presentation can loop instead of shutting off.

     

    Hope this helps,

    Jack

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mconners
    0 mconners over 10 years ago in reply to jack.chaney56

    I was about to suggest a similar solution. The more unixy way of solving this problem is to use a semaphore.

     

    gj, jack.chaney56

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • brew
    0 brew over 10 years ago in reply to jack.chaney56

    Hi Jack,

     

    that's the problem at the moment you can double press the button, and the presentation runs twice, any idea how I instigate the semaphore?

     

    Cheers

    Brew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 10 years ago in reply to brew

    Not that I understand Python, but couldn't you check to see if the goshow process is running before calling it again?

    This might help (not tried it): http://stackoverflow.com/questions/6780035/python-how-to-run-ps-cax-grep-something-in-python 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jack.chaney56
    0 jack.chaney56 over 10 years ago in reply to brew

    Hi James,  If you want to have the presentation not repeat, then ignore the counter component.  Just have a "handshake" flag. The routine that recognizes the SW1 press, checks for an off state to start the presentation and sets the state on. If it is on, it just ignores the press. Upon completion of the presentation, turn the state to off.

     

    Delayed response behavior, kind of like kids image,

    Jack

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago

    Python has no semaphore flag hence a file system is easy to write and test for. Hint: I have done this before and it works well.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • brew
    0 brew over 10 years ago

    This is my code

     

    #!/usr/bin/python

    import pifacedigitalio

    import subprocess

     

    pfd = pifacedigitalio.PiFaceDigital()

     

    pfd.leds[5].turn_on() #Room light ON

     

    def toggle_led0(event):

      subprocess.call("/home/pi/goshow.sh", shell=True)

     

    pifacedigital = pifacedigitalio.PiFaceDigital()

    listener = pifacedigitalio.InputEventListener(chip=pifacedigital)

    listener.register(0, pifacedigitalio.IODIR_FALLING_EDGE, toggle_led0)

    listener.activate()

     

    This is my first foray into this so apologies if it is obvious, sorry i just don't know how to do it.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 10 years ago in reply to brew

    Reading and Writing Files in Python all you need. I will return shortly.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mconners
    0 mconners over 10 years ago in reply to clem57

    Technically, what you are suggesting is a file based semaphore. Although historically these were not recommended due to overhead, this is probably not as concerning these days, but performance should always be a consideration.

     

    Both python 2 and python 3 have support for semaphores in the threading and or asyncio libraries respectively.

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube