title: Pi run command and wait
body: <p>I'm new to this so please bear with me.
  I'm trying to write a piece of code to run a command, when relay closes a circuit and another when it opens.
  I've altered a sample piece of code I've found and it seems to do most of what I want.
  I've set it up to run mp3's while I'm test/learning.
  but my problem is that I only want it to play the corresponding mp3 once, but it keeps playing the mp3 over an over again.</p>
  
  <p>I thought about using time time.sleep() and using a large number so theres a long pause.
  but the circuit may close in that time and it won't play the mp3 in that time.</p>
  
  <p>here's my code</p>
  
  <pre><code>import os
  import time
  
  import RPi.GPIO as GPIO
  
  GPIO.setmode(GPIO.BCM)
  
  GPIO.setwarnings(False)
  GPIO.setup(22, GPIO.IN)
  
  print("------------------")
  print("   trigger test   ")
  print("------------------")
  
  print GPIO.input(22)
  
  while True:
     if ( GPIO.input(22) == False ):
        print("Triggered")
        os.system('omxplayer -o hdmi cow.mp3')
     else:
        print ("Waiting to be triggered again")
        os.system('omxplayer -o hdmi sample.mp3')
  </code></pre>