What I'm trying to do is have my main code run a timer and then physical hardware causes interrupts to trigger a movie clip to play. But I'm having two issues with my interrupts. 1) the interrupt gets called, but runs the function twice. I don't think it's a debounce issue because I have upped the debounce to be pretty long - and also it always runs exactly twice, never once, never three times. 2) the second problem as I'm trying to expand my integreation is that the interrupt gets called whether my input GPIO pin is 3.3V or GND. I expect it to only get triggered when it moves from ground to 3.3V, but that's not what's happening.
If anyone can help with either I would be very appreciative. Code below.
Code: Select all
#!/usr/bin/python from Tkinter import * import RPi.GPIO as GPIO import time import escapeFunctions GPIO.setmode(GPIO.BCM) GPIO.cleanup() GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) poorly = ("/home/pi/Videos/poorly.mp4") wisely = ("/home/pi/Videos/wisely.mp4") rootWindow = Tk() def int17(pin17): escapeFunctions.playVideoFun(poorly) def int18(pin18): escapeFunctions.playVideoFun(wisely) GPIO.add_event_detect(17, GPIO.RISING, callback=int17, bouncetime=3000) GPIO.add_event_detect(18, GPIO.RISING, callback=int18, bouncetime=3000) # Gets the requested values of the height and widht. windowWidth = rootWindow.winfo_reqwidth() windowHeight = rootWindow.winfo_reqheight() # print("Width",windowWidth,"Height",windowHeight) # Gets both half the screen width/height and window width/height positionRight = int(rootWindow.winfo_screenwidth() / 2 - windowWidth / 2) positionDown = int(rootWindow.winfo_screenheight() / 2 - windowHeight / 2) # defaultColour = rootWindow.cget("red") rootWindow.attributes("-fullscreen", True) time1 = '' prevSec = '' mins = 0 secs = 0 hours = 0 running = True # clock = Label(rootWindow, font=('fixed', 20, 'bold')) clock = Label(rootWindow, font=('fixed', 100)) clock.grid(row=1, column=2, padx=positionRight / 2, pady=positionDown) # clock.config(bg='dark red') clock.config(fg='red') def tick(): global prevSec, time1, secs, mins, hours, running # get the current local time from the PC # time2 = time.strftime('%Y/%m/%d %H:%M:%S') if running: newSec = time.strftime('%S') else: newSec = '' prevSec = '' if newSec != prevSec: prevSec = newSec secs = secs + 1 if secs > 59: secs = 0 mins = mins + 1 if mins > 59: mins = 0 hours = hours + 1 if hours > 1: # hours = 0 # mins = 0 # secs = 0 clock.config(bg='black') # clock = Label(rootWindow, font=('fixed', 150)) time2 = '%02d:%02d:%02d' % (hours, mins, secs) # if time string has changed, update it if time2 != time1: time1 = time2 clock.config(text=time2) # calls itself every 200 milliseconds # to update the time display as needed # could use >200 ms, but display gets jerky clock.after(200, tick) tick() rootWindow.mainloop()
Code: Select all
def playVideoFun (fileName): import os os.system ('omxplayer ' + fileName) return