Zeit schätzen
Programmiere ein einfaches Spiel und errate die gewünschte Zeitspanne.
Bewege die Maus über die blauen Zeilennummern und erhalte mehr Informationen.
1 | # -*- coding: utf-8 -*- |
2 | import sys |
3 | sys.path.append('/home/pi/raspbotics/Pythonboard_Module/RFID') |
4 | sys.path.append('/home/pi/raspbotics/Pythonboard_Module/LED_Matrix') |
5 | sys.path.append('/home/pi/raspbotics/Pythonboard_Module') |
6 | from RPi import GPIO |
7 | GPIO.setmode(GPIO.BCM) |
8 | import time |
9 | |
10 | Taster = 5 |
11 | LEDgruen = 22 |
12 | LEDrot = 17 |
13 | |
14 | GPIO.setup(Taster,GPIO.IN,pull_up_down=GPIO.PUD_DOWN) |
15 | GPIO.setup(LEDgruen,GPIO.OUT) |
16 | GPIO.setup(LEDrot,GPIO.OUT) |
17 | |
18 | GPIO.output(LEDgruen,0) |
19 | GPIO.output(LEDrot,0) |
20 | |
21 | try: |
22 | while 1: |
23 | print "Drücken Sie den Taster und schätzen Sie 5 Sekunden" |
24 | print "Danach drücken Sie den Taster erneut" |
25 | while GPIO.input(Taster)!=1: |
26 | pass |
27 | start = time.time() |
28 | print "Timer gestartet" |
29 | time.sleep(0.3) |
30 | while GPIO.input(Taster)!=1: |
31 | pass |
32 | stop = time.time() |
33 | time.sleep(0.3) |
34 | Zeitdauer = round((stop - start),1) |
35 | print "Der Timer wurde nach " + str(Zeitdauer) + " Sekunden gestoppt" |
36 | if (Zeitdauer > 4.5) and (Zeitdauer < 5.5): |
37 | GPIO.output(LEDgruen,1) |
38 | time.sleep(1) |
39 | GPIO.output(LEDgruen,0) |
40 | else: |
41 | GPIO.output(LEDrot,1) |
42 | time.sleep(1) |
43 | GPIO.output(LEDrot,0) |
44 | |
45 | time.sleep(3) |
46 | print "" |
47 | print "-------------------------" |
48 | print "" |
49 | except KeyboardInterrupt: |
50 | GPIO.cleanup() |