I have this piece of code:
#!/usr/bin/env python #coding: utf8 import RPi.GPIO as GPIO from picamera import PiCamera from time import sleep camera = PiCamera() # pin-count GPIO.setmode(GPIO.BOARD) # Pin 18 (GPIO 24) as input GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # loop while 1: # read input if GPIO.input(18) == GPIO.HIGH: # if input = high start recording camera.start_recording('video.h264') # PIN 16 (GPIO23) as input GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # loop while 1: # read input if GPIO.input(16) == GPIO.HIGH: # if input = high stop recording camera.stop_recording
If pin 18 is 1 (1.3+V) the recording should start but it just won't. I tried the exact same code with
camera.start_preview / camera.stop_preview
as code for pin 18 / 16 and it worked like a charm. I know that error comes up because I'm looping the "camera.start_recording" part but I don't now how to do this without the loop. If I try this without loopin it just starts recording as soon as I start the script. But I need it to start as soon as the pin counts as "high". Any Idea how I could do that?