SunFounder Da Vinci Kit
timer1.cancel()
time.sleep(1)
gameState
=
(gameState+1)%2
def
loop():
global
counter
currentState
=
lastState
=
0
while
True:
display()
currentState=GPIO.input(sensorPin)
if
(currentState
stateChange()
lastState=currentState
def
timer():
global
counter
global
timer1
timer1
=
threading.Timer(0.01, timer)
timer1.start()
counter
+=
1
def
setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(SDI, GPIO.OUT)
GPIO.setup(RCLK, GPIO.OUT)
GPIO.setup(SRCLK, GPIO.OUT)
for
i
in
placePin:
GPIO.setup(i, GPIO.OUT)
GPIO.setup(sensorPin, GPIO.IN)
def
destroy():
# When "Ctrl+C" is pressed, the function is executed.
GPIO.cleanup()
global
timer1
timer1.cancel()
if
__name__
==
'__main__':
setup()
try:
loop()
except
KeyboardInterrupt:
destroy()
Code Erklärung
def
stateChange():
global
gameState
global
counter
global
timer1
if
gameState
==
counter
=
0
time.sleep(1)
timer()
elif
gameState ==1:
timer1.cancel()
time.sleep(1)
gameState
=
(gameState+1)%2
382
0
==
0)
and
(lastState
# Program starting from here
0:
==
1):
Kapitel 1. Über das Da Vinci Kit
(Fortsetzung der vorherigen Seite)