My program is for a raspberry pi project in which I give a user the option to record messages when they press a button. My current goal is to have a while loop give the option of recording by pressing the button and then exiting the loop, and if it is not pressed for 5 seconds it exits the loop.
Here is what my code looks like:
w = True
while w:
# if the button on the pi is pressed once this while loop begins,
if GPIO.input(17) == 0:
print ("Button Pressed")
sleep(2)
print ("Explaining recording instructions")
pygame.mixer.Sound.play(record_s)
sleep(8)
print ("Recording")
record_audio()
# Exit the loop once message is recorded by pressing the button once more
if GPIO.input(17) == 0:
w = False
# If the button is not pressed for 5 seconds,
elif sleep(5):
print ("No input")
# Exit the loop
w= False
I have tried several different methods, done lots of googling and looked at similar questions but none of them have worked.