import RPi.GPIO as GPIO
import os
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
# 버튼 설정
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# 버튼을 누를 때 호출되는 콜백 함수
def take_picture(channel):
timestamp = time.strftime("%Y%m%d_%H%M%S")
os.system(f'fswebcam -r 2048x1536 --no-banner /home/pi/pictures/{timestamp}.jpg')
print(f"Picture taken: {timestamp}.jpg")
# GPIO 19번 핀에 falling edge detection을 추가하고, debounce 시간 설정
GPIO.add_event_detect(19, GPIO.FALLING, callback=take_picture, bouncetime=300)
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
import RPi.GPIO as GPIO
import os
import time
import pygame
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
# 버튼 설정
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# pygame 초기화
pygame.init()
pygame.mixer.init()
# 오디오 알림 함수
def play_notification():
pygame.mixer.music.load("/home/pi/aiot/notification.mp3") # <--- 경로 수정
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
time.sleep(0.1)
# 버튼을 누를 때 호출되는 콜백 함수
def take_picture(channel):
play_notification()
time.sleep(2) # 오디오 알림이 끝날 때까지 대기 (필요한 경우 조절)
timestamp = time.strftime("%Y%m%d_%H%M%S")
os.system(f'fswebcam -r 2048x1536 --no-banner /home/pi/pictures/{timestamp}.jpg')
print(f"Picture taken: {timestamp}.jpg")
# GPIO 19번 핀에 falling edge detection을 추가하고, debounce 시간 설정
GPIO.add_event_detect(19, GPIO.FALLING, callback=take_picture, bouncetime=300)
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
pygame.mixer.quit()
GPIO.cleanup()
Copyright ⓒ TECH79 All right reserved