2022-10-03 20:47:06 +02:00
|
|
|
#!/bin/python3 -u
|
2022-07-16 22:49:24 +02:00
|
|
|
|
2022-10-03 20:47:06 +02:00
|
|
|
## -U option log to syslog on systemctl
|
|
|
|
|
|
|
|
import RPi.GPIO as GPIO
|
2022-07-16 22:49:24 +02:00
|
|
|
import pygame
|
|
|
|
import threading
|
2022-10-03 20:47:06 +02:00
|
|
|
from datetime import datetime, timedelta
|
2022-07-16 22:49:24 +02:00
|
|
|
import time
|
2022-10-03 20:47:06 +02:00
|
|
|
import random
|
2022-07-16 22:49:24 +02:00
|
|
|
|
2022-10-03 20:47:06 +02:00
|
|
|
## Define sounds path
|
|
|
|
intro = "/home/museoa/INTRO_CHIMES.mp3"
|
|
|
|
night = "/home/museoa/MEP_NOCHE.mp3"
|
|
|
|
|
|
|
|
# Define mute hours
|
|
|
|
# From 9.00 to 21.00
|
|
|
|
open_hour = 9
|
|
|
|
close_hour = 21
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _play(path):
|
2022-07-16 22:49:24 +02:00
|
|
|
if not pygame.mixer.music.get_busy() :
|
2022-10-03 20:47:06 +02:00
|
|
|
pygame.mixer.music.load(path)
|
|
|
|
pygame.mixer.music.play(0,0.0)
|
2022-07-16 22:49:24 +02:00
|
|
|
while pygame.mixer.music.get_busy():
|
|
|
|
pygame.time.Clock().tick(10)
|
2022-10-03 20:47:06 +02:00
|
|
|
print("Ended Sound");
|
|
|
|
pygame.mixer.music.stop()
|
|
|
|
|
|
|
|
|
|
|
|
def play_sound():
|
|
|
|
print("play now..")
|
|
|
|
sounds = [night]
|
|
|
|
if not pygame.mixer.music.get_busy() :
|
|
|
|
print("Start Sound")
|
|
|
|
_play(intro)
|
|
|
|
_play(random.choice(sounds))
|
2022-07-16 22:49:24 +02:00
|
|
|
else :
|
|
|
|
print("Stop Sound")
|
2022-10-03 20:47:06 +02:00
|
|
|
pygame.mixer.music.fadeout(5)
|
2022-07-16 22:49:24 +02:00
|
|
|
|
|
|
|
def button_callback(channel):
|
|
|
|
print("Button was pushed!")
|
|
|
|
|
2022-10-03 20:47:06 +02:00
|
|
|
# from 9.00 to 21.00
|
|
|
|
now = datetime.now()
|
|
|
|
if (now.hour < close_hour and now.hour >= open_hour):
|
|
|
|
x = threading.Thread(target=play_sound)
|
|
|
|
x.start()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
## init pygame
|
|
|
|
pygame.mixer.init()
|
|
|
|
|
|
|
|
GPIO.setwarnings(False) # Ignore warning for now
|
|
|
|
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
|
|
|
|
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulled low (off)
|
|
|
|
GPIO.add_event_detect(10,GPIO.RISING,callback=button_callback, bouncetime=10000) # Setup event on pin 10 rising edge 10s wait
|
|
|
|
|
|
|
|
while (True):
|
|
|
|
## Play schedule
|
|
|
|
now = datetime.now()
|
|
|
|
## 20:00 AM
|
|
|
|
if (now.hour == 20 and now.minute == 0):
|
|
|
|
_play(intro)
|
|
|
|
_play(night)
|
|
|
|
|
|
|
|
time.sleep(60)
|
2022-07-16 22:49:24 +02:00
|
|
|
|
2022-10-03 20:47:06 +02:00
|
|
|
GPIO.cleanup() # Clean up
|
2022-07-16 22:49:24 +02:00
|
|
|
|
2022-10-03 20:47:06 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|