I am using the GPIO pins on my Raspberry Pi with a PIR sensor to detect motion. When the sensor detects motion I want to then move the software onto other functions.
You could wrap the GPIO-code into it's own thread and have the rest of your program do something else while the GPIO is waiting for input. Check out the threading module
First I'd wrap your code into a function
def wait_input():
var=1
counter = 0
while var == 1:
if GPIO.input(7):
counter += 1
time.sleep(0.5)
else:
counter = 0
time.sleep(1)
if counter >= 3:
print "Movement!"
captureImage()
time.sleep(20)
And then in your main program you could something like this
input_thread = threading.Thread(target = wait_input)
input_thread.start()
# do something in the meanwhile
input_thread.join()
There are plenty of questions on SO concerning python threading, so you might want to dig them up. Please note that there are also plenty of things to consider when using threads, especially in python which has a global interpreter lock (GIL) which allows only one process to run at a time. It might also be smart to check out the multiprocessing module with which one can route around the GIL.