I want to assign 2 different function to button1, and another function to button2, like this example:
button1 press --> function A
button1 press --> function B
button1 press --> function A
button1 press --> function B
whenever i press button 2 --> function C.
I tried with this code:
Code: Select all
#!/usr/bin/env python2.7
import RPi.GPIO as GPIO
import os
import time
GPIO.setmode(GPIO.BCM)
# setting gpios
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
print "\n button2 pressed"
GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=500)
try:
while True:
GPIO.wait_for_edge(14, GPIO.FALLING)
print "\n button 1 pressed"
sleep.time(0.5)
GPIO.wait_for_edge(14, GPIO.FALLING)
print "\n button 1 pressed again"
sleep.time(0.5)
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()Is there another way for doing what I want?
I figured that using GPIO.add_event_detect allow me to call just a single callback, so i moved on GPIO.wait_for_edge in an infinite loop, although this method is not working.