Skip to content

Instantly share code, notes, and snippets.

@danya02
Last active August 8, 2016 08:31
Show Gist options
  • Save danya02/06374d7290db76479a42c4c50d65a502 to your computer and use it in GitHub Desktop.
Save danya02/06374d7290db76479a42c4c50d65a502 to your computer and use it in GitHub Desktop.
The code for the button-detecting circuit that people can understand.
import gpiozero
import threading
import time
b=gpiozero.Button(21)
global presses
global prss
global timed
presses=0
prss=0
timed=False
def cycle():
global presses
global prss
global timed
timed=True
time.sleep(5)
timed=False
if presses>3:
presses=3
prss=presses
def press():
global presses
global timed
if timed:
presses+=1
b.when_pressed=press
threading.Thread(target=cycle).start()
while prss==0:
pass
print(prss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment