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()
Copyright ⓒ TECH79 All right reserved