I have been working on a project that will allow me to take picture using a switch. So for that purpose i setup the GPIO and all necesseary tools for that code, Python-dev and etc.
When i run the code to control only the LED it works perfectly, i press the button, the LED turns on, and when i let go of the switch the LED turns off.
However the issue starts when i try to add the camera module to the code, when i add all other stuff like take a picture and prompt ls -l, the code does not wait for me to press the switch, instead it takes picture itself over and over again. I am am using rpi2 with latest version of raspian.
FYI I updated and upgraded the raspberry pi2.
What am i doing wrong? here is the code
import picamera
import time
import RPi.GPIO as GPIO
import subprocess
from subprocess import call
#def main():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #pull down
GPIO.setup(7, GPIO.OUT) #setup the LED for Processing
GPIO.output(7,0)
def blink():
GPIO.output(7,1)
time.sleep(1)
GPIO.output(7,0)
time.sleep(1)
def camera():
subprocess.call(["sudo", "python", "cameratest.py"])
call(["ls", "-l"])
try:
while True:
if GPIO.input(11) == 1: #gpio input first button
blink()
camera()
else:
GPIO.output(7,0) #if button false turn down the$
except KeyboardInterrupt:
GPIO.cleanup()