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 4764 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
Parents
  • 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
Reply
  • 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
Children
  • 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
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