feat: control relay
This commit is contained in:
33
relay.py
33
relay.py
@@ -1,41 +1,22 @@
|
|||||||
#! /usr/bin/python3
|
#! /usr/bin/python3
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from omxplayer.player import OMXPlayer
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Config those variables
|
# Config those variables
|
||||||
v1 = Path('/home/pi/Videos/2.mp4')
|
|
||||||
v2 = Path('/home/pi/Videos/2.mp4')
|
|
||||||
PIN = 12
|
PIN = 12
|
||||||
SWITCH_AT = 9*60 + 16
|
|
||||||
VOLUME = 1.5
|
|
||||||
|
|
||||||
def play():
|
|
||||||
print('play')
|
|
||||||
try:
|
|
||||||
player = OMXPlayer(v1, args=['--display=2'], dbus_name='org.mpris.MediaPlayer2.omxplayer1')
|
|
||||||
p2 = OMXPlayer(v2, args=['--display=7'], dbus_name='org.mpris.MediaPlayer2.omxplayer2')
|
|
||||||
LENGTH = player.duration()
|
|
||||||
player.set_volume(VOLUME)
|
|
||||||
time.sleep(SWITCH_AT)
|
|
||||||
GPIO.output(PIN, GPIO.LOW)
|
|
||||||
time.sleep(LENGTH - SWITCH_AT)
|
|
||||||
return True
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
return False
|
|
||||||
finally:
|
|
||||||
GPIO.output(PIN, GPIO.HIGH)
|
|
||||||
player.quit()
|
|
||||||
p2.quit()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while play():
|
time.sleep(5)
|
||||||
pass
|
GPIO.output(PIN, GPIO.LOW)
|
||||||
|
time.sleep(5)
|
||||||
|
GPIO.output(PIN, GPIO.HIGH)
|
||||||
|
time.sleep(5)
|
||||||
|
GPIO.output(PIN, GPIO.LOW)
|
||||||
|
time.sleep(5)
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
GPIO.setmode(GPIO.BOARD)
|
GPIO.setmode(GPIO.BOARD)
|
||||||
#GPIO.setwarnings(False)
|
|
||||||
GPIO.setup(PIN, GPIO.OUT, initial=GPIO.HIGH)
|
GPIO.setup(PIN, GPIO.OUT, initial=GPIO.HIGH)
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user