Last active
August 8, 2016 08:31
-
-
Save danya02/06374d7290db76479a42c4c50d65a502 to your computer and use it in GitHub Desktop.
The code for the button-detecting circuit that people can understand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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