Modifying Video recorder script ,add time sleep and led

Hello, I’m still a beginner :slight_smile: Could you help me?

I would like to put a “time sleep” for button noise reduce in this script because there are disturbing signals / Noise / before the button is pressed. False GPIO triggers, sometimes it starts on its own. And add one led when the script starts / ready / and another when button is pushed, the recording starts .Its used on RP 3+
Thanks for your helping:)

import datetime
import picamera
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)

while True:
GPIO.wait_for_edge(24, GPIO.FALLING)
        dvrname = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
        with picamera.PiCamera() as camera:
camera.resolution = (1920, 1080)
camera.start_preview()
camera.start_recording('/home/pi/' + dvrname + '.h264')
GPIO.wait_for_edge(24, GPIO.RISING)
camera.stop_recording()
GPIO.cleanup()`

Please fix the indentation.

It’s a bad idea to trigger on an edge because of the problem of button bounce. It would be better to read the level periodically and start/stop recording if it’s the same level for a reasonable amount of time.

1 Like