using tkinter i have made a GUI in which a video plays continuously in a loop until the ultrasonic sensor detects a person in front of it. when a person is detected it displays a messages"hi..welcome". everything works fine but after running for around 20 minutes the raspberry pi freezes with blank black display.
import random
from tkinter import *
import tkinter as tk
from PIL import ImageTk, Image
import time
from datetime import datetime
from subprocess import call
from time import sleep
import serial
import RPi.GPIO as GPIO
import time
import os
import sys
from subprocess import Popen
movie1 = ("/home/pi/1.mp4")
last_state1 = True
quit_video = True
player = False
GPIO.setmode(GPIO.BCM)
TRIG = 23
ECHO = 24
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
window1 = tk.Tk()
window1.overrideredirect(1)
window1.geometry("900x1200")
window1.configure(background="black")
def create_main_window():
def off():
window.destroy()
on()
window = tk.Tk()
window.overrideredirect(1)
window.geometry("900x1200")
window.configure(background="black")
w1 = Label(window, text="Hi..WELCOME..", bg="black", fg="white", font="Times 110")
w1.place(relx=.5, rely=.4, anchor="c")
window.after(2000, off)
window.mainloop()
def on():
player = False
timeout = time.time() + 50
while True:
GPIO.output(TRIG, False)
print ("wating for sensor to settle")
time.sleep(1)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
distance = round(distance, 2)
if distance > 1 and distance < 150:
print ("Distance:",distance - 0.5, "cm")
os.system('killall omxplayer.bin')
create_main_window()
else:
if not player:
os.system('killall omxplayer.bin')
omxc = Popen(['omxplayer', '-b', movie1])
player = True
else:
print("hi")
if time.time() > timeout:
on()
window1.after(2000, on)
window1.mainloop()