I have a python program that loops through some GPIO commands. How can I break the loop at any time during the loop by pressing the Enter key. So far I have this...
import sys
import select
import os
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
i = 0
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print "I'm doing stuff. Press Enter to stop me!"
print i
GPIO.output(3, GPIO.HIGH)
time.sleep(1)
GPIO.output(3, GPIO.LOW)
time.sleep(1)
GPIO.output(3, GPIO.HIGH)
time.sleep(1)
GPIO.output(3, GPIO.LOW)
time.sleep(1)
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
line = raw_input()
break
i += 1
This works but once pressing Enter to break the loop I have to wait until the GPIO.output commands have finished before the loop will break. I want it to break immediately.