2 actions on one button


6 posts
by lpdescamps » Fri Nov 02, 2012 1:19 pm
Hi,

I'm try to play/pause mpc using a momentary push button connected on the gpio.

i guess python would do that nicely but i m just hopeless ....

the code based on other codes I found on the forums is

Code: Select all
import RPi.GPIO as GPIO
import time
import os

GPIO.setmode(GPIO.BCM)
GPIO.setup (17, GPIO.IN)

while True:
   if not GPIO.input(17):
      active = 'pause'
      time.sleep(.1)
      if GPIO.input(17):
         while active == 'pause':
             os.system('mpc pause')
            GPIO.output(12,False)
            if not GPIO.input(17):
               if GPIO.input(17):
                  time.sleep(.1)
                  active = 'pause'
   else:
      GPIO.output(12,True)
       os.system('mpc play')


but of course doesnt work :-)

any advice would be appreciated

Thank you
Posts: 3
Joined: Fri Nov 02, 2012 1:13 pm
by KenT » Fri Nov 02, 2012 5:47 pm
Have a look at this thread. The programs in the OP do button de-bouncing and edge detection, you may need one or both of these. if you are a python beginner use the non-gui version.

http://www.peteronion.org.uk/smf/index.php?topic=108.0
Pi Presents - A toolkit to produce multi-media interactive displays for museums, visitor centres, and more
Download from http://pipresents.wordpress.com
Posts: 597
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
by lpdescamps » Sat Nov 03, 2012 6:06 pm
Hi Ken,

thanks for your reply. how do i see the script from the link?
thanks
Posts: 3
Joined: Fri Nov 02, 2012 1:13 pm
by lpdescamps » Mon Nov 05, 2012 1:27 pm
this seems to work. what do you think? thanks

Code: Select all
import RPi.GPIO as GPIO
import time
import os

GPIO.setmode(GPIO.BCM)
GPIO.setup (17, GPIO.IN)

while True:
    if GPIO.input(17):
      os.system('mpc pause')
      time.sleep(.5)
    if GPIO.input(17):
      os.system('mpc play')
      time.sleep(.5)

Posts: 3
Joined: Fri Nov 02, 2012 1:13 pm
by KenT » Mon Nov 05, 2012 6:28 pm
The buttons programs are attachments to my first post in the thread
Pi Presents - A toolkit to produce multi-media interactive displays for museums, visitor centres, and more
Download from http://pipresents.wordpress.com
Posts: 597
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
by mparrott82 » Thu Nov 08, 2012 1:26 pm
KenT wrote:The buttons programs are attachments to my first post in the thread


Do you have to register to be able to view your attachments? I cannot see a way to get them, no clickable link.
Posts: 16
Joined: Wed Aug 29, 2012 10:12 pm