# coding: UTF-8 import subprocess,datetime,time import RPi.GPIO as GPIO # ピンの指定方法 GPIO.setmode(GPIO.BCM) # GPIO25 GPIO.setup(25, GPIO.IN) # ボタンクリック待機中 print("ボタン待機中...") while (True): # 割り込み処理(ボタンを押す&立ち上がりを検知) GPIO.wait_for_edge(25, GPIO.RISING) # ボタンの長押しを検知するためのカウンター cnt = 0; while (True): if GPIO.input(25) == GPIO.LOW: print("ボタンが押されました") # 合成音声を再生するための関数 def voice_play(voice_path): subprocess.call("sudo aplay " + voice_path, shell=True) # 日時の取得 dt_now = datetime.datetime.now() hour = dt_now.hour min = dt_now.minute print(str(hour) + "時" + str(min) + "分") # コメントの再生 voice_file = "./voice/kazumakun.wav" voice_play(voice_file) # 今の時間は voice_file = "./voice/now.wav" voice_play(voice_file) # 時間ボイスの再生 voice_file = "./voice/hour_" + str(hour) + ".wav" voice_play(voice_file) # 分ボイスの再生 voice_file = "./voice/min_" + str(min) + ".wav" voice_play(voice_file) # です voice_file = "./voice/desu.wav" voice_play(voice_file) # おやつのじかん if (hour == 15 and min <= 30): voice_file = "./voice/oyatu_yes.wav" else: voice_file = "./voice/oyatu_no.wav" voice_play(voice_file) # よるごはん if (hour == 18 and min <= 59): voice_file = "./voice/dinner.wav" voice_play(voice_file) # ねんね if (hour == 21 or hour == 20): voice_file = "./voice/nenne.wav" voice_play(voice_file) break else: cnt = cnt + 1 if (cnt >= 250): print("長押し検知:シャットダウン") subprocess.call("sudo shutdown -h now", shell=True) break time.sleep(0.01)