Corsasri
Posts: 99
Joined: Sat Mar 07, 2015 9:40 am

Help with my script.

Sun Jun 28, 2020 9:56 am

my script is run on startup at rc.local. Everything works fine except one problem, When the video plays with a button press it shows the terminal text on screen for a second. but if i type clear in the terminal the text is then removed. i have tried adding clear() to my script but then dose not work as it did when i typed it manually. Do you know what i could try ?

Code: Select all

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os
import random

GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)

os.system ("omxplayer --no-osd --loop --win '0 0  707 475' /home/pi/video/still.mp4 &")

def blink(ledpin):
    GPIO.output(ledpin,GPIO.HIGH)
    time.sleep(float(random.randrange(1,10,1))/10)
    GPIO.output(ledpin,GPIO.LOW)
    time.sleep(float(random.randrange(1,10,1))/10)

def play_video1():
    print ("GPIO11")
    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --vol +450.00dB --win '0 0 707 475' -r -o local /home/pi/video/1.mp4 &")
    start_time = time.time()
    while (GPIO.input(11) == False) and (time.time()-start_time < 178):
        blink(13)

    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --no-osd --loop --win '0 0 707 475' -o local /home/pi/video/still.mp4 &")

def play_video2():
    print ("GPIO15")
    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --vol +450.00db --win  '0 0 707 475' -r -o local  /home/pi/video/2.mp4 &")
    start_time = time.time()
    while (GPIO.input(15) == False) and (time.time()-start_time < 78):
        blink(13)

    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --no-osd --loop --win '0 0 707 475' -o local /home/pi/video/still.mp4 &")

def play_video3():
    print ("GPIO7")
    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --vol +450.00db --win  '0 0 707 475' -r -o local  /home/pi/video/3.mp4 &")
    start_time = time.time()
    while (GPIO.input(7) == False) and (time.time()-start_time < 1195):
        blink(13)

    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --no-osd --loop --win '0 0 707 475' -o local /home/pi/video/still.mp4 &")

def play_video4():
    print ("GPIO16")
    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --vol +450.00dd --win '0 0 707 475' -r -o local /home/pi/video/4.mp4 &")
    start_time = time.time()
    while (GPIO.input(16) == False) and (time.time()-start_time < 178): 
        blink(13)

    print ("sudo killall omxplayer.bin")
    os.system("sudo killall omxplayer.bin")
    os.system ("omxplayer --no-osd --loop --win '0 0 707 475' -o local /home/pi/video/still.mp4 &")



while True:
    input_state = GPIO.input(11)
    if input_state == False:
        time.sleep(0.5)
        input_state = GPIO.input(11)
        if input_state == False:
            play_video1()

    input_state = GPIO.input(15)
    if input_state == False:
        time.sleep(0.5)
        input_state = GPIO.input(15)
        if input_state == False:
            play_video2()

    input_state = GPIO.input(7)
    if input_state == False:
        time.sleep(0.5)
        input_state = GPIO.input(7)
        if input_state == False:
            play_video3()

    input_state = GPIO.input(16)
    if input_state == False:
        time.sleep(0.5)
        input_state = GPIO.input(16)
        if input_state == False:
            play_video4()
    

GPIO.cleanup()
clear()

User avatar
kerry_s
Posts: 740
Joined: Thu Jan 30, 2020 7:14 pm

Re: Help with my script.

Sun Jun 28, 2020 10:03 am

have you tried putting clear in rc.local

Corsasri
Posts: 99
Joined: Sat Mar 07, 2015 9:40 am

Re: Help with my script.

Sun Jun 28, 2020 10:27 am

kerry_s wrote:
Sun Jun 28, 2020 10:03 am
have you tried putting clear in rc.local
Thank you. That has helped by adding to rc.local. But if i add it at the end of " & " it dose not work and if i remove " &" it works but my splash screen stays there.
This works but splach screen sticks

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
python3 /home/pi/mytracker/motion.py 
clear
exit 0
if its like this the terminal text stays

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
python3 /home/pi/mytracker/motion.py &
clear
exit 0

Return to “Beginners”